#define errors

M

mohan

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
 
L

Lucien Kennedy-Lamb

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
 
M

mohan

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
 
L

Logan Shaw

mohan said:
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
 
L

Lucien Kennedy-Lamb

Logan said:
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
 
J

Jaspreet

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

#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 ?
 
J

Jaspreet

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

#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 ?
 
J

Jaspreet

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

#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 ?
 
M

Mark McIntyre

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
 
M

mohan

thanks a lot
Lucien Kennedy-Lamb said:
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
 

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,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top