#define errors

Discussion in 'C Programming' started by mohan, Jan 17, 2006.

  1. mohan

    mohan Guest

    Hi All.

    I have error message

    #include <stdio.h>

    #define NAV_FORMAT_VERSION 10

    #define OC_LM_ANNOT 1

    #define OC_LM_SHAPE 0

    #define OC_EXIST_MASK OC_LM_ANNOT | \

    #if NAV_FORMAT_VERSION == 10

    OC_LM_SHAPE

    #endif

    int main()

    {

    if ( OC_EXIST_MASK)

    printf( " Defined");

    else

    printf( " Not defined ");

    return 0;

    }



    Kindly let me know my mistake....



    Mohan
    mohan, Jan 17, 2006
    #1
    1. Advertising

  2. You don't mention what the error is but I suspect it's an unexpected
    #endif.

    A trailing \ on a #define has a special meaning and includes the next
    line as part of the #define. This means the following #if ... line
    doesn't have any effect.

    It still won't compile - what was your intention here?

    Lucien Kennedy-Lamb
    Lucien Kennedy-Lamb, Jan 17, 2006
    #2
    1. Advertising

  3. mohan

    mohan Guest

    error message is as follows

    --------------------------------------------

    "macro.c", line 8: syntax error before or at: |

    "macro.c", line 9: #if-less #endif

    "macro.c", line 14: invalid source character: '#'

    "macro.c", line 14: syntax error before or at: if

    cc: acomp failed for macro.c



    -------------------------------------------------------------------

    "Lucien Kennedy-Lamb" <> wrote in message
    news:...
    > You don't mention what the error is but I suspect it's an unexpected
    > #endif.
    >
    > A trailing \ on a #define has a special meaning and includes the next
    > line as part of the #define. This means the following #if ... line
    > doesn't have any effect.
    >
    > It still won't compile - what was your intention here?
    >
    > Lucien Kennedy-Lamb
    >
    mohan, Jan 17, 2006
    #3
  4. mohan

    mohan Guest

    i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
    defined


    "Lucien Kennedy-Lamb" <> wrote in message
    news:...
    > You don't mention what the error is but I suspect it's an unexpected
    > #endif.
    >
    > A trailing \ on a #define has a special meaning and includes the next
    > line as part of the #define. This means the following #if ... line
    > doesn't have any effect.
    >
    > It still won't compile - what was your intention here?
    >
    > Lucien Kennedy-Lamb
    >
    mohan, Jan 17, 2006
    #4
  5. mohan

    Logan Shaw Guest

    mohan wrote:
    > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
    > defined


    I'm fairly sure you can't put an #if in the right-hand side of a #define.

    - Logan
    Logan Shaw, Jan 17, 2006
    #5
  6. Logan Shaw wrote:
    > mohan wrote:
    > > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
    > > defined

    >
    > I'm fairly sure you can't put an #if in the right-hand side of a #define.
    >
    > - Logan


    Your right Logan. All preprocessor directives must start on their own
    line and can't be constructed by other preprocessor directives.

    The preprocessor won't recursively parse the source file.

    I think your solution is:

    #if NAV_FORMAT_VERSION == 10
    #define OC_EXIST_MASK (OC_LM_ANNOT | OC_LM_SHAPE)
    #else
    #define OC_EXIST_MASK OC_LM_ANNOT
    #endif

    Lucien Kennedy-Lamb
    Lucien Kennedy-Lamb, Jan 17, 2006
    #6
  7. mohan

    Jaspreet Guest

    mohan wrote:
    > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
    > defined
    >
    >
    > "Lucien Kennedy-Lamb" <> wrote in message
    > news:...
    > > You don't mention what the error is but I suspect it's an unexpected
    > > #endif.
    > >
    > > A trailing \ on a #define has a special meaning and includes the next
    > > line as part of the #define. This means the following #if ... line
    > > doesn't have any effect.
    > >
    > > It still won't compile - what was your intention here?
    > >
    > > Lucien Kennedy-Lamb
    > >


    #if NAV_FORMAT_VERSION == 10
    #define OC_LM_SHAPE 0
    #endif

    OR

    You could also use the #ifdef macro.

    However, I still could not understand what you meant by the statement:
    #define OC_EXIST_MASK OC_LM_ANNOT | \

    With what do you want to OR the OC_LM_ANNOT flag ?
    Jaspreet, Jan 17, 2006
    #7
  8. mohan

    Jaspreet Guest

    mohan wrote:
    > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
    > defined
    >
    >
    > "Lucien Kennedy-Lamb" <> wrote in message
    > news:...
    > > You don't mention what the error is but I suspect it's an unexpected
    > > #endif.
    > >
    > > A trailing \ on a #define has a special meaning and includes the next
    > > line as part of the #define. This means the following #if ... line
    > > doesn't have any effect.
    > >
    > > It still won't compile - what was your intention here?
    > >
    > > Lucien Kennedy-Lamb
    > >


    #if NAV_FORMAT_VERSION == 10
    #define OC_LM_SHAPE 0
    #endif

    Or you also use #ifdef macro.

    However i still could not understand what you meant by:
    #define OC_EXIST_MASK OC_LM_ANNOT | \

    With what do you want to OR the OC_LM_ANNOT flag to ?
    Jaspreet, Jan 17, 2006
    #8
  9. mohan

    Jaspreet Guest

    mohan wrote:
    > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
    > defined
    >
    >
    > "Lucien Kennedy-Lamb" <> wrote in message
    > news:...
    > > You don't mention what the error is but I suspect it's an unexpected
    > > #endif.
    > >
    > > A trailing \ on a #define has a special meaning and includes the next
    > > line as part of the #define. This means the following #if ... line
    > > doesn't have any effect.
    > >
    > > It still won't compile - what was your intention here?
    > >
    > > Lucien Kennedy-Lamb
    > >


    #if NAV_FORMAT_VERSION == 10
    #define OC_LM_SHAPE 0
    #endif

    Or you also use #ifdef macro.

    However i still could not understand what you meant by:
    #define OC_EXIST_MASK OC_LM_ANNOT | \

    With what do you want to OR the OC_LM_ANNOT flag to ?
    Jaspreet, Jan 17, 2006
    #9
  10. On Tue, 17 Jan 2006 10:47:45 +0530, in comp.lang.c , "mohan"
    <> wrote:

    >i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
    >defined


    #if defined (NAV_FORMAT_VERSION)
    #define OC_LM_SHAPE
    #endif

    Also...

    >#define OC_EXIST_MASK OC_LM_ANNOT | \


    what are the trailing |\ doing there?

    >#if NAV_FORMAT_VERSION == 10
    >OC_LM_SHAPE
    >#endif


    Remember that macros are literally replaced in the code by their
    value. So this translates into

    #if 10 == 10
    0
    #endif

    which is a syntax error


    Mark McIntyre
    --

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Jan 17, 2006
    #10
  11. mohan

    mohan Guest

    thanks a lot
    "Lucien Kennedy-Lamb" <> wrote in message
    news:...
    >
    > Logan Shaw wrote:
    > > mohan wrote:
    > > > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
    > > > defined

    > >
    > > I'm fairly sure you can't put an #if in the right-hand side of a

    #define.
    > >
    > > - Logan

    >
    > Your right Logan. All preprocessor directives must start on their own
    > line and can't be constructed by other preprocessor directives.
    >
    > The preprocessor won't recursively parse the source file.
    >
    > I think your solution is:
    >
    > #if NAV_FORMAT_VERSION == 10
    > #define OC_EXIST_MASK (OC_LM_ANNOT | OC_LM_SHAPE)
    > #else
    > #define OC_EXIST_MASK OC_LM_ANNOT
    > #endif
    >
    > Lucien Kennedy-Lamb
    >
    mohan, Jan 18, 2006
    #11
    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. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    937
    Mark Goldin
    Jan 17, 2004
  2. SenthilVel
    Replies:
    0
    Views:
    936
    SenthilVel
    Jun 7, 2006
  3. theotyflos
    Replies:
    3
    Views:
    463
    Thomas Matthews
    Feb 19, 2004
  4. robin liu
    Replies:
    3
    Views:
    821
    Robin Liu
    Apr 21, 2006
  5. Brian Takita

    #define _ and #define __

    Brian Takita, Jan 23, 2006, in forum: Ruby
    Replies:
    0
    Views:
    457
    Brian Takita
    Jan 23, 2006
Loading...

Share This Page