Author Topic: C11 .. C89 .. ?  (Read 2568 times)

Offline dxcarnadi

  • Single posting newcomer
  • *
  • Posts: 4
C11 .. C89 .. ?
« on: June 14, 2016, 10:24:05 am »
Hello

I'm learning (by myself) C with a book from Ivor Horton "Beginning C".
As IDE I use Code::Block in Windows-10.

I tried to compile/build an example from that book .. got the error messages.
Please see the attachment.
Why .. the errors?
What should I do?
Thank you for your help.
« Last Edit: June 14, 2016, 01:23:15 pm by dxcarnadi »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2979
Re: C11 .. C89 .. ?
« Reply #1 on: June 14, 2016, 11:40:35 am »
The error is pretty clear: "initial decelerations are only allowed in C99 and onward"

so in your code you have something like this:
Code
for(int i = 0; i < 3;++i)

prior to the C99 standard it was not allowed do declare your variable in the for loop header.
To fix this you can use the following code:
Code
int i = 0;
for(i= 0;i< 3;++i)

or you compile with c99 enabled:
Project->Build options
make sure you have selected the top most entry in the tree control on the left
Compiler settings->Compiler flags-> Make a tick at "Have gcc follow the 1999 ISO C lang......" -> OK
rebuild your project by
Build->Rebuild

greetings