Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #13957 > unrolled thread
| Started by | glen herrmannsfeldt <gah@ugcs.caltech.edu> |
|---|---|
| First post | 2012-02-13 02:08 +0000 |
| Last post | 2012-02-13 20:27 +1300 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.c++
The or operator and the preprocessor? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-02-13 02:08 +0000
Re: The or operator and the preprocessor? Ian Collins <ian-news@hotmail.com> - 2012-02-13 15:59 +1300
Re: The or operator and the preprocessor? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-02-13 05:32 +0000
Re: The or operator and the preprocessor? Ian Collins <ian-news@hotmail.com> - 2012-02-13 20:27 +1300
| From | glen herrmannsfeldt <gah@ugcs.caltech.edu> |
|---|---|
| Date | 2012-02-13 02:08 +0000 |
| Subject | The or operator and the preprocessor? |
| Message-ID | <jh9ra0$2h3$1@speranza.aioe.org> |
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 );
}
}
[toc] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-02-13 15:59 +1300 |
| Message-ID | <9prck4F2i6U1@mid.individual.net> |
| In reply to | #13957 |
On 02/13/12 03:08 PM, glen herrmannsfeldt wrote:
> 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.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | glen herrmannsfeldt <gah@ugcs.caltech.edu> |
|---|---|
| Date | 2012-02-13 05:32 +0000 |
| Message-ID | <jha79h$mlb$1@speranza.aioe.org> |
| In reply to | #13958 |
Ian Collins <ian-news@hotmail.com> wrote: (snip, I wrote) >> error: "or" cannot be used as a macro name as it is an operator in C++ (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
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-02-13 20:27 +1300 |
| Message-ID | <9prsabF2i6U2@mid.individual.net> |
| In reply to | #13960 |
On 02/13/12 06:32 PM, glen herrmannsfeldt wrote: > Ian Collins<ian-news@hotmail.com> wrote: > > (snip, I wrote) > >>> error: "or" cannot be used as a macro name as it is an operator in C++ > > (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. "or" is an operator, not a keyword. -- Ian Collins
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web