Why doesn't GCC like it?

I am trying to learn C and find myself very stuck, no complaints :)

Anyway, I wrote a program and GCC doesn't like it. The following code is NOT a program, but it demonstrates the problem:

#define MAXLINE = 1000

int main()
{
   int tmp = MAXLINE;
   char line[MAXLINE];

   return 0;
}

      

When it is compiled I get the following error:

test.c: 7: error: expected expression before '= token

If you replace the symbolic constant MAXLINE with int 1000, everything works.

What's happening?

+2


source to share


7 replies


When the preprocessor replaces your definition MAXLINE

, your code changes to

int main()
{
   int tmp = = 1000;
   char line[= 1000];
   return 0;
}

      



The C preprocessor is very dumb! Don't add anything extra to #defines (no equals, no semicolons, nothing)

+21


source


Definitions don't need equal signs :)



#define maxline 1000

      

+20


source


Shouldn't be = just in the definition

#define MAXLINE 1000

      

+10


source


The operator #define

does not need an equal sign.

He should read:

#define MAXLINE 1000

+3


source


Use #define without '=':

#define MAXLINE 1000

      

+3


source


You have

#define MAXLINE 1000

      

You can read more here http://gcc.gnu.org/onlinedocs/cpp/Object_002dlike-Macros.html#Object_002dlike-Macros

+3


source


#define MAXLINE 1000

      

+1


source







All Articles