Ad
  • Default User Avatar

    GCC does not conform to any ANSI/ISO standards, if that isn't a problem for you, your employer, etc game on. C++ is an object oriented language derived from C. C is not an object oriented language. Being object oriented, C++ has many more tools in its libraries for declaration of objects including dynamically allocated arrays. My comment was not in response to a solution in C++. You can learn the way that works some of the time or the way that works all of the time.

  • Custom User Avatar

    Why such reaction tho? GCC supports VLAs since, like, forever, even in C++. For non-MSVC part of the world they are probably not that surprising?

  • Default User Avatar

    "int tills[n]" declares a variable-length array (VLA) which was not implemented until the C99 standard and was relegated in C11. MSVC, for example, does not support VLA. Depending on what compiler you are using and the standards it conforms to (or avoids) attempting to decalare a VLA in C may throw an error. As I understand it, the reason this support was removed is due to the vulnerability it introduces to stack based buffer overflow exploits. Using malloc or calloc from stdlib will ensure you don't run into errors while compiling in other environments.

    My comment was not meant to mock anyone, it was more of a reaction to the fact that the compiler here actually lets you get away with it.

  • Default User Avatar

    If you mock beginners for bad practice, it'd be nice to explain what's wrong about it.

  • Default User Avatar

    I see a lot of solutions using variables to declare arrays in C "int tills[n]; ". Good luck getting that to compile in the real world.