-1

When compiling in c, the compiler is giving me a warning telling me that C90 forbids mixing declaration and code, however their is no case of this in my code and the line that it says the warning occurs at is clearly just the declaration of a variable their is no code mixed with it.

This is what my compiler shows

gcc -c Functions.c -Wall -ansi -pedantic
Functions.c:27:18: warning: ISO C90 forbids mixing declarations and code
      [-Wdeclaration-after-statement]
        LinkedListNode* curr;
                        ^
1 warning generated.

This is my function where the warning is occurring

BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70
Cameron
  • 75
  • 1
  • 1
  • 6
  • 2
    Paste your code into the question, don't put it in an image. But in C90, you have to put your declarations at the top of a scope, before any code. – Fred Larson Oct 25 '17 at 21:23
  • I don't think @FredLarson meant to paste the image... – Steve Oct 25 '17 at 21:26
  • 1
    I couldn't even see the image, just a text placeholder. My employer's proxy blocks the image hosting site. – Fred Larson Oct 25 '17 at 21:27
  • Note that the name of the `gcc` option that disables this warning is even more descriptive than the text of the warning itself: `-Wdeclaration-after-statement`. It is complaining that at least one of your declarations appears after one or more executable statements. This is allowed in C99 and later, but was forbidden in C90. – John Bollinger Oct 25 '17 at 21:37
  • Two options: tell your compiler to accept C99 (it's been 18 years, you really should upgrade), or move all your declarations to the top of the function: it's your `int i` that's the problem. Move it to the top of the function. – Lee Daniel Crocker Oct 25 '17 at 21:41
  • if you have choice, get a newer compiler. this should not be the case i think in later standard. – Jason Hu Oct 25 '17 at 21:41
  • Use `-std=c99` instead of `-ansi`. Thank you for pointing out. @JohnBode – BLUEPIXY Oct 25 '17 at 22:20

1 Answers1

0

In fact there is code inbetween your declarations, the offending line being arraySize = list->numElements. You can move that line further down, after LinkedListNode *curr declaration or merge it with the declaration of arraySize the line before, like this: int arraySize = list->numElements.

lukeg
  • 4,189
  • 3
  • 19
  • 40