473,382 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

#define errors

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
Jan 17 '06 #1
10 1963
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

Jan 17 '06 #2
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" <lu*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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

Jan 17 '06 #3
i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
defined
"Lucien Kennedy-Lamb" <lu*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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

Jan 17 '06 #4
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
Jan 17 '06 #5

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

Jan 17 '06 #6
mohan wrote:
i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
defined
"Lucien Kennedy-Lamb" <lu*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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 ?

Jan 17 '06 #7
mohan wrote:
i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
defined
"Lucien Kennedy-Lamb" <lu*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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 ?

Jan 17 '06 #8
mohan wrote:
i wanted to include symbol OC_LM_SHAPE only when NAV_FORMAT_VERSION is
defined
"Lucien Kennedy-Lamb" <lu*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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 ?

Jan 17 '06 #9
On Tue, 17 Jan 2006 10:47:45 +0530, in comp.lang.c , "mohan"
<mo**********@in.bosch.com> 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 =----
Jan 17 '06 #10
thanks a lot
"Lucien Kennedy-Lamb" <lu*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

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

Jan 18 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: prettysmurfed | last post by:
Hi all I have this, probably stupid question, how to avoid multiple definitions when a header file is included more than once. I thought, when you wrote the header-file and used the...
6
by: David T. Ashley | last post by:
Hi, In my project, I typically declare and define variables in the .H file, i.e. DECMOD_MAIN UINT8 can_message_201_status_global #ifdef MODULE_MAIN = HAS_NEVER_BEEN_RECEIVED #endif ;
34
by: BQ | last post by:
Hello Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant, is greater than 35, it returns 56, if not, 20. I would like that at compile time, not at run time. ...
5
by: Alex Vinokur | last post by:
Here are two programs. --- foo1.c --- #include <assert.h> #define FOO 10 int main() { assert (15 < FOO); return 0; }
57
by: Mike Malone | last post by:
A colleague of mine is proposing that we use a set of preprocessor definitions to make our C code more readable: #define BEGIN { #define ENG } #define EQ == etc. My initial...
2
by: huey_jiang | last post by:
Hi All, I need to make DLL for my new hash function in C. In myhashdll.c file, I have a function as: char *make_hash(char *in, char *out) { ...... ...... return (out);
42
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
2
by: Luis Arvayo | last post by:
I am compiling and executing c# code at runtime and I need to define in CompilerParameters.ReferencedAssemblies one of my own assemblies together with the standard System.dll u others. Example:...
4
by: venkat | last post by:
I have come across some preprossor statements, such as #define PPTR_int #define PPTR_str #define DDAR_baddr & #define DDAR_caddr & What do they mean, but when i compile the code with these...
23
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.