learnclang / screencast-rps

Rock Paper Scissors in C
9 stars 2 forks source link

Fix for loop initial declarations (pre C99 mode) #2

Closed csaez closed 9 years ago

Byron commented 9 years ago

Thanks, why not !

mottosso commented 9 years ago

In the interest of learning, would it be possible to include a little description of the changes?

csaez commented 9 years ago

Before C99, you had to define the local variables at the start of a block. C99 imported the C++ feature that you can intermix local variable definitions with the instructions and you can define variables in the for and while control expressions.

By default, gcc does not conform to any of the ANSI/ISO C standards. The current default is equivalent to -std=gnu90, which is the 1989/1990 standard with GNU-specific extensions.

tl;dr @Byron's code works fine as long as you explicity compile in C99 mode (or higher) using the flag -std=C99, changes allow to compile using gnu90 (gcc's default).

Byron commented 9 years ago

And I have kind of overwritten these changes when I re-recorded the screencast. Maybe at some point, we add a build system that 'does it correctly' on all platforms, or everyone builds with qt-creator for now which uses a C++ compiler (unfortunately).

csaez commented 9 years ago

You can create a Makefile from qtcreator project files (.pro) usingqmake :+1:

I have recommended the use of a standard building system since we started sharing code without much luck (everyone wants to use a homemade script), perhaps screencasts are able to make a better case.