Discussion Overview
The discussion revolves around resolving an "undefined reference" error when calling functions from a .o file in C/C++. It also explores the complexities of using dynamically allocated multi-dimensional arrays and pointers in C and C++, including how to access elements with multiple subscripts.
Discussion Character
- Technical explanation
- Debate/contested
- Mathematical reasoning
Main Points Raised
- One participant encounters an "undefined reference" error when trying to call a function from a .o file and seeks help.
- Another participant suggests checking the compilation command to ensure the .o file is properly linked.
- A participant resolves their initial issue by identifying a capitalization error in the function name.
- Discussion shifts to accessing elements of a dynamically allocated 2D array using pointers, with one participant questioning if two subscripts can be used with a pointer to the first element.
- Some participants explain that C does not support multi-dimensional arrays in the traditional sense, as they are stored in a one-dimensional format in memory.
- One participant argues that if only a pointer to the first element is available, accessing elements with two subscripts is not feasible without additional information about the array's dimensions.
- Another participant provides examples of how to declare and use pointers for multi-dimensional arrays in C++, emphasizing the importance of understanding the difference between arrays of pointers and true multi-dimensional arrays.
- There is a discussion about the limitations of Microsoft compilers regarding dynamic allocation of multi-dimensional arrays, with some participants suggesting alternatives like using vectors of pointers.
- One participant asserts that their code for creating a dynamically allocated 2D array works and questions the validity of the opposing viewpoint.
- Clarifications are made regarding the distinction between multi-dimensional arrays and ragged arrays, highlighting differences in memory allocation and access methods.
- Some participants discuss the need for a pointer to a pointer to access elements in a dynamically allocated array structure properly.
Areas of Agreement / Disagreement
Participants express differing views on the feasibility of using pointers to access elements of dynamically allocated arrays, particularly regarding the limitations imposed by certain compilers. There is no consensus on the best approach to handle multi-dimensional arrays in C/C++, and the discussion remains unresolved.
Contextual Notes
Participants mention various methods for allocating and accessing multi-dimensional arrays, but the discussion reveals limitations based on compiler behavior and the nature of the arrays being used. The complexity of pointer arithmetic and memory management in C/C++ is also highlighted.