Macro assignmnet to a variable

S

saleem

I have two macros in a.h file

like #define DEVPKTTYPE 0x00
#define ETHPKTTYPE 0x01


when I am including this file
in main program i.e main.c

#include " a.h"

and trying to assign it to a variable

int type = DEVPKTTYPE;

I am getting the compiler error saying parse error before line number
specifying this line (int type = DEVPKTTYPE)

but when I am doing the #defines itself in main.c file

like
#define DEVPKTTYPE 0x00
#define ETHPKTTYPE 0x01

main()
{
int type = DEVPKTTYPE;
}

I am not facing the parse error. what was the problem while I included
the a.h file. please help me.
 
A

Alexei A. Frounze

saleem said:
I have two macros in a.h file

like #define DEVPKTTYPE 0x00
#define ETHPKTTYPE 0x01


when I am including this file
in main program i.e main.c

#include " a.h"

and trying to assign it to a variable

int type = DEVPKTTYPE;

I am getting the compiler error saying parse error before line number
specifying this line (int type = DEVPKTTYPE)

What is *before* this line? Maybe there's an error somewhere in the a.h file
(in the middile or in the end), which happens to be processed exactly before
the line you showed us.
but when I am doing the #defines itself in main.c file

like
#define DEVPKTTYPE 0x00
#define ETHPKTTYPE 0x01

main()
{
int type = DEVPKTTYPE;
}

I am not facing the parse error. what was the problem while I included
the a.h file. please help me.

This code is either incomplete or to some degree incorrect (missing the int
return type in definition of main()). But other than that there's no
problem.

Alex
 
T

tanmoy87544

...snipped rest of the quote ...
This code is either incomplete or to some degree incorrect (missing the int
return type in definition of main()). But other than that there's no
problem.

Not incorrect, technically, but old style C which is not recommended.
 
M

Mike Wahler

saleem said:
I have two macros in a.h file

like #define DEVPKTTYPE 0x00
#define ETHPKTTYPE 0x01


when I am including this file
in main program i.e main.c

#include " a.h"

Did you really have a space in your literal?
Perhaps that's the trouble.
and trying to assign it to a variable

int type = DEVPKTTYPE;

I am getting the compiler error saying parse error before line number
specifying this line (int type = DEVPKTTYPE)

but when I am doing the #defines itself in main.c file

like
#define DEVPKTTYPE 0x00
#define ETHPKTTYPE 0x01

main()
{
int type = DEVPKTTYPE;
}

I am not facing the parse error. what was the problem while I included
the a.h file. please help me.

Well, logically (if you're presenting accurate information),
there's something wrong in your header, or with the directive
which includes it.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top