#define errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mohan

    #1

    #define errors

    Hi All.

    I have error message

    #include <stdio.h>

    #define NAV_FORMAT_VERS ION 10

    #define OC_LM_ANNOT 1

    #define OC_LM_SHAPE 0

    #define OC_EXIST_MASK OC_LM_ANNOT | \

    #if NAV_FORMAT_VERS ION == 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


  • Lucien Kennedy-Lamb

    #2
    Re: #define errors

    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

    Comment

    • mohan

      #3
      Re: #define errors

      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" <lucien0@gmail. com> wrote in message
      news:1137474660 .942737.57980@o 13g2000cwo.goog legroups.com...[color=blue]
      > 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
      >[/color]


      Comment

      • mohan

        #4
        Re: #define errors

        i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERS ION is
        defined


        "Lucien Kennedy-Lamb" <lucien0@gmail. com> wrote in message
        news:1137474660 .942737.57980@o 13g2000cwo.goog legroups.com...[color=blue]
        > 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
        >[/color]


        Comment

        • Logan Shaw

          #5
          Re: #define errors

          mohan wrote:[color=blue]
          > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERS ION is
          > defined[/color]

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

          - Logan

          Comment

          • Lucien Kennedy-Lamb

            #6
            Re: #define errors


            Logan Shaw wrote:[color=blue]
            > mohan wrote:[color=green]
            > > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERS ION is
            > > defined[/color]
            >
            > I'm fairly sure you can't put an #if in the right-hand side of a #define.
            >
            > - Logan[/color]

            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_VERS ION == 10
            #define OC_EXIST_MASK (OC_LM_ANNOT | OC_LM_SHAPE)
            #else
            #define OC_EXIST_MASK OC_LM_ANNOT
            #endif

            Lucien Kennedy-Lamb

            Comment

            • Jaspreet

              #7
              Re: #define errors

              mohan wrote:[color=blue]
              > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERS ION is
              > defined
              >
              >
              > "Lucien Kennedy-Lamb" <lucien0@gmail. com> wrote in message
              > news:1137474660 .942737.57980@o 13g2000cwo.goog legroups.com...[color=green]
              > > 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
              > >[/color][/color]

              #if NAV_FORMAT_VERS ION == 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 ?

              Comment

              • Jaspreet

                #8
                Re: #define errors

                mohan wrote:[color=blue]
                > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERS ION is
                > defined
                >
                >
                > "Lucien Kennedy-Lamb" <lucien0@gmail. com> wrote in message
                > news:1137474660 .942737.57980@o 13g2000cwo.goog legroups.com...[color=green]
                > > 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
                > >[/color][/color]

                #if NAV_FORMAT_VERS ION == 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 ?

                Comment

                • Jaspreet

                  #9
                  Re: #define errors

                  mohan wrote:[color=blue]
                  > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERS ION is
                  > defined
                  >
                  >
                  > "Lucien Kennedy-Lamb" <lucien0@gmail. com> wrote in message
                  > news:1137474660 .942737.57980@o 13g2000cwo.goog legroups.com...[color=green]
                  > > 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
                  > >[/color][/color]

                  #if NAV_FORMAT_VERS ION == 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 ?

                  Comment

                  • Mark McIntyre

                    #10
                    Re: #define errors

                    On Tue, 17 Jan 2006 10:47:45 +0530, in comp.lang.c , "mohan"
                    <mohan.bhakri@i n.bosch.com> wrote:
                    [color=blue]
                    >i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERS ION is
                    >defined[/color]

                    #if defined (NAV_FORMAT_VER SION)
                    #define OC_LM_SHAPE
                    #endif

                    Also...
                    [color=blue]
                    >#define OC_EXIST_MASK OC_LM_ANNOT | \[/color]

                    what are the trailing |\ doing there?
                    [color=blue]
                    >#if NAV_FORMAT_VERS ION == 10
                    >OC_LM_SHAPE
                    >#endif[/color]

                    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 =----

                    Comment

                    • mohan

                      #11
                      Re: #define errors

                      thanks a lot
                      "Lucien Kennedy-Lamb" <lucien0@gmail. com> wrote in message
                      news:1137476694 .308427.121770@ g14g2000cwa.goo glegroups.com.. .[color=blue]
                      >
                      > Logan Shaw wrote:[color=green]
                      > > mohan wrote:[color=darkred]
                      > > > i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERS ION is
                      > > > defined[/color]
                      > >
                      > > I'm fairly sure you can't put an #if in the right-hand side of a[/color][/color]
                      #define.[color=blue][color=green]
                      > >
                      > > - Logan[/color]
                      >
                      > 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_VERS ION == 10
                      > #define OC_EXIST_MASK (OC_LM_ANNOT | OC_LM_SHAPE)
                      > #else
                      > #define OC_EXIST_MASK OC_LM_ANNOT
                      > #endif
                      >
                      > Lucien Kennedy-Lamb
                      >[/color]


                      Comment

                      Working...