0

I have noticed a very strange behavior when I try to define variable that has type long long int.

For example, code written this way works fine:

#include <stdio.h>

#define STR_LEN 20

int main()
{  
    long long broj = 1;

    char str[STR_LEN];
    scanf("%s", str);

    return 0;
}

But, code written this way cannot be compiled:

#include <stdio.h>

#define STR_LEN 20

int main()
{  
    char str[STR_LEN];
    scanf("%s", str);

    long long broj = 1;

    return 0;
}

Compiler provides following message: error C2143: syntax error : missing ';' before 'type' which is not very helpful... I am using Visual Studio 2010.

Any thoughts about this behavior? Thanks.

3 Answers3

1

In Visual Studio 2010(C89),always initialize variables at the start of the program.

Spikatrix
  • 20,225
  • 7
  • 37
  • 83
0

Any thoughts about this behavior?

Yes. Visual Studio 2010 doesn't support the mix type declaration. Compile your code with GCC in C99 mode (use option -std=c99) and it will work fine. ISO C99 and ISO C++ allow declarations and code to be freely mixed within compound statements.
As an extension, GCC also allows this in C89 mode

haccks
  • 104,019
  • 25
  • 176
  • 264
  • Yes, I tried compiling it with GCC compiler and it works fine in both C89 and C99 mode. Thanks, this is probably the answer. – LittleAlien May 28 '14 at 09:36
0
  1. long is a qualifier not a type, you are not explicitly declaring a type at all
  2. historically, Windows/Visual Studio doesn't offer good support for C
  3. you are not mentioning the options that you are using to compile this
user2485710
  • 9,451
  • 13
  • 58
  • 102