![]() |
|
|
Welcome to the { mindfrost82.com } forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
does g++ treat 'and' as a keyword?
my g++ version is 4.2.3.
when i use word 'and'(or, not) as a variable name or function name, g+ + compiles error with the following message: test.cpp:5: error: expected unqualified-id before ‘&&’ token test.cpp:5: error: expected initializer before ‘&&’ token test.cpp:6: error: expected identifier before ‘)’ token it seems that g++ treats 'and' as a keyword for operator "&&", but as long as i know it is not. how can i disable this feature for g++ -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: does g++ treat 'and' as a keyword?
zade wrote:
> my g++ version is 4.2.3. > > when i use word 'and'(or, not) as a variable name or function name, g+ > + compiles error with the following message: > > test.cpp:5: error: expected unqualified-id before ?&&? token > test.cpp:5: error: expected initializer before ?&&? token > test.cpp:6: error: expected identifier before ?)? token > > it seems that g++ treats 'and' as a keyword for operator "&&", but as > long as i know it is not. > > how can i disable this feature for g++ > It's most likely #defined as '&&' in one of the header files. Once upon a time it was quite fashionable for people moving over from PASCAL. They has something like #define begin { #define end } #define and && #define or || etc.. <insert sentimental *sigh* here /> HTH O. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: does g++ treat 'and' as a keyword?
zade schrieb:
> my g++ version is 4.2.3. > > when i use word 'and'(or, not) as a variable name or function name, g+ > + compiles error with the following message: > > test.cpp:5: error: expected unqualified-id before ?&&? token > test.cpp:5: error: expected initializer before ?&&? token > test.cpp:6: error: expected identifier before ?)? token > > it seems that g++ treats 'and' as a keyword for operator "&&", but as > long as i know it is not. Sorry, "and" "or" and "not" are C++ keywords, so are bitand, compl not_eq, or_eq, xor_eq, and_eq, bitor, xor So long, Thomas -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: does g++ treat 'and' as a keyword?
Hi
zade wrote: > it seems that g++ treats 'and' as a keyword for operator "&&", but as > long as i know it is not. Well, 'and' is an alternative token for &&. There are others, like 'or' (||), 'bitor' (|), 'not' (!), or 'xor_eq' (^=). There are even trigraphs for denoting "uncommon" characters, like '??=' for '#', so that you can write '??=include <vector>' instead of '#include <vector>'. (in that context, look up why the trigraph '??/' is especially dreadful) There might be a way to turn all these off, but that's completely platform specific. Markus -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: does g++ treat 'and' as a keyword?
On 2008-08-01 17:58, zade wrote:
> my g++ version is 4.2.3. > > when i use word 'and'(or, not) as a variable name or function name, g+ > + compiles error with the following message: > > test.cpp:5: error: expected unqualified-id before �&&� token > test.cpp:5: error: expected initializer before �&&� token > test.cpp:6: error: expected identifier before �)� token > > it seems that g++ treats 'and' as a keyword for operator "&&", but as > long as i know it is not. > > how can i disable this feature for g++ It is a "feature" of the C++ language and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq are all alternative representations of the operators and should not be used in code. -- Erik Wikström [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: does g++ treat 'and' as a keyword?
On Aug 1, 11:58 am, zade <zhaohongc...@gmail.com> wrote:
> my g++ version is 4.2.3. > > when i use word 'and'(or, not) as a variable name or function name, g+ > + compiles error with the following message: > > test.cpp:5: error: expected unqualified-id before ‘&&’ token > test.cpp:5: error: expected initializer before ‘&&’ token > test.cpp:6: error: expected identifier before ‘)’ token > > it seems that g++ treats 'and' as a keyword for operator "&&", but as > long as i know it is not. They're standard. Sorry. They're in lex.key.2 in the standard. Sean -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: does g++ treat 'and' as a keyword?
zade <zhaohongchao@gmail.com> wrote in news:be809a11-e998-45f4-b71f-
90c5d7c0e00b@o40g2000prn.googlegroups.com: > my g++ version is 4.2.3. > > when i use word 'and'(or, not) as a variable name or function name, g+ > + compiles error with the following message: > > test.cpp:5: error: expected unqualified-id before ?&&? token > test.cpp:5: error: expected initializer before ?&&? token > test.cpp:6: error: expected identifier before ?)? token > > it seems that g++ treats 'and' as a keyword for operator "&&", but as > long as i know it is not. > > how can i disable this feature for g++ > Ummmmm, I hate to break this to you, but 'and' is a reserved word representing && in the standard. They are in an table of alternative representations in [lex.key]/2. Other words in this category are: and_eq bitand bitor compl not not_eq or or_eq xor and xor_eq I would guess that there isn't an explicit option in g++ to disable part of the standard. joe -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: does g++ treat 'and' as a keyword?
zade wrote:
> my g++ version is 4.2.3. > > when i use word 'and'(or, not) as a variable name or function name, > g+ + compiles error with the following message: > > test.cpp:5: error: expected unqualified-id before $B!&(B&$B!&(Btoken > test.cpp:5: error: expected initializer before $B!&(B&$B!&(Btoken > test.cpp:6: error: expected identifier before $B!&!&(Btoken > > it seems that g++ treats 'and' as a keyword for operator "&&", but > as long as i know it is not. > > how can i disable this feature for g++ The standard really defines these alternate names for operators. The compiler is quite correct in recognizing them. With g++, you can turn them off using -fno-operator-names Doing so will make your code less portable though. Bo Persson -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: does g++ treat 'and' as a keyword?
zade ha scritto:
> my g++ version is 4.2.3. > > when i use word 'and'(or, not) as a variable name or function name, g+ > + compiles error with the following message: > > test.cpp:5: error: expected unqualified-id before �&&� token > test.cpp:5: error: expected initializer before �&&� token > test.cpp:6: error: expected identifier before �)� token > > it seems that g++ treats 'and' as a keyword for operator "&&", but as > long as i know it is not. g++ is correct. Although "and" is not a keyword, as it's not listed in table 3 in 2.11, it's an "alternative token representation" of &&. The two spellings are therefore completely equivalent. > > how can i disable this feature for g++ > Frankly I don't know, but you shouldn't try to do that if you want your code to be portable. HTH, Ganesh -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: does g++ treat 'and' as a keyword?
Oncaphillis wrote:
> It's most likely #defined as '&&' in one of the > header files. Once upon a time it was quite fashionable > for people moving over from PASCAL. They has something > like > > #define begin { > #define end } > #define and && > #define or || > > etc.. > I'm shocked to learn that this is BS "and" is a key word. Never came across that.. :-( O. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|