Pergunta

I wrote a program for an assignment in which I allocated memory in this way: EdgeBucket* edgeTable[ n_scanlines ];. I understand that this is normally illegal in C, but I was not aware that it could also not be done in C++. However, when I compile it using g++, it gives no compile errors. But my grader is using a visual studio, and when he attempted to build my program, it gave errors stating that the length of the array must be constant. I normally compile my programs with the -ansi and -Wall options to ensure cross compiler integrity, but even that didn't detect this. I am concerned about my grades being compromised by this, so does anyone know why the -ansi compiler didn't catch this, and what can be done to prevent further cross compiler discrepancies?

Foi útil?

Solução

Use -pedantic-errors flag. Example.

They are known as VLAs (Variable Length Arrays). The are legal in C from C99 and illegal in C++.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top