The or operator and the preprocessor?

  • Thread starter glen herrmannsfeldt
  • Start date
G

glen herrmannsfeldt

error: "or" cannot be used as a macro name as it is an operator in C++

In C, the preprocessor does what its name says, and occurs before
the compiler sees tokens and reserved words.

Is that not true in C++?

extern "C" {
#include <stdio.h>
#define or "hi there!\n"
int main() {
printf( or );
}
}
 
I

Ian Collins

error: "or" cannot be used as a macro name as it is an operator in C++

In C, the preprocessor does what its name says, and occurs before
the compiler sees tokens and reserved words.

Is that not true in C++?

extern "C" {
#include<stdio.h>
#define or "hi there!\n"
int main() {
printf( or );
}
}

The error is valid, "or" is the alternative token for "||" in C++.
Redefining it is a bad idea.
 
G

glen herrmannsfeldt

(snip, I wrote)
(snip)

The error is valid, "or" is the alternative token for "||" in C++.

Oh, so also valid in preprocessor statements?

So might cause problems similar to:

#define x define

#x y 1
Redefining it is a bad idea.

Well, that is probably true of all the language keywords.
In most cases, though, it should't cause problems if you don't
use the keyword.

-- glen
 
I

Ian Collins

(snip, I wrote)


Oh, so also valid in preprocessor statements?

So might cause problems similar to:

#define x define

#x y 1


Well, that is probably true of all the language keywords.

"or" is an operator, not a keyword.
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top