Macro assignmnet to a variable

Discussion in 'C Programming' started by saleem, Oct 7, 2005.

  1. saleem

    saleem Guest

    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.
    saleem, Oct 7, 2005
    #1
    1. Advertising

  2. "saleem" <> wrote in message
    news:...
    >
    > 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
    Alexei A. Frounze, Oct 7, 2005
    #2
    1. Advertising

  3. saleem

    Guest

    Alexei A. Frounze wrote:
    > > main()

    ...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.
    , Oct 7, 2005
    #3
  4. saleem

    Mike Wahler Guest

    "saleem" <> wrote in message
    news:...
    >
    > 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
    Mike Wahler, Oct 7, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marc Schellens

    assignmnet to int form float/double

    Marc Schellens, Dec 7, 2003, in forum: C++
    Replies:
    9
    Views:
    437
    Andrey Tarasevich
    Dec 9, 2003
  2. Dead RAM
    Replies:
    20
    Views:
    1,094
    John Harrison
    Jul 14, 2004
  3. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    565
    Jack Klein
    Sep 21, 2003
  4. sounak

    to get macro name from macro value

    sounak, Nov 22, 2005, in forum: C Programming
    Replies:
    17
    Views:
    486
    Mark McIntyre
    Nov 22, 2005
  5. John Reye
    Replies:
    14
    Views:
    764
    Tim Rentsch
    May 8, 2012
Loading...

Share This Page