I demonstrate for one of Prof Richard Bowden's modules on C programming for first year Electronic Engineering students. Recently one of the tasks given to students was read in a matrix, multiply and write it out. To start with they did 3x3 then 7x7 then were instructed to make it variable size.
So when going round to help I showed a few of them how to allocate deallocate dynamic memory then asked the question had they been taught this. Apparently at they hadnt by this point, later finding out it comes up after Christmas.
My ramblings today are not about the module content or structure but actually the gcc compiler. When learning to program in C++ I learnt on a fairly sensible compiler inside Visual Studio. Then hit the gcc compiler and got annoyed by stupid things, for example
Visual Studio interprets this fine
std::vector<std::vector<int>>
g++
Error, required:
std::vector<std::vector<int> >
To note the space between the last two angle brackets.
While walking round I saw some students code and got a little scare by it they performed operations such as:
int size = 0;
scanf("%i",size);
int myArray[size];
for (int i = 0 ; i < size ; i++)
scanf("%f",myArray[i]);
for (int i = 0 ; i < size ; i++)
printf("%f",myArray[i]);
To my horror this compiled without warning or error and even worse it worked. I later while chatting to friends found that this was normal for the gcc compiler, and apparently the g++. So therefore we had some guesses about how this would work and the common answer was:
myArray is initialised to length 0, then since taken of the stack when read and written to you corrupted the stack.
The message to take away from this horror story of teaching C, is two things use a compiler that may not follow the letter of the standard but actually is intelligent and knows what you mean; always use -wall when compiling on gcc otherwise you will end up in a pile of mess later on!