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.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > C++

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-01-2008, 04:58 PM
zade
 
Posts: n/a
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! ]

Reply With Quote
  #2 (permalink)  
Old 08-01-2008, 08:33 PM
Oncaphillis
 
Posts: n/a
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! ]

Reply With Quote
  #3 (permalink)  
Old 08-01-2008, 08:34 PM
Thomas Richter
 
Posts: n/a
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! ]

Reply With Quote
  #4 (permalink)  
Old 08-01-2008, 08:34 PM
Markus Moll
 
Posts: n/a
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! ]

Reply With Quote
  #5 (permalink)  
Old 08-01-2008, 08:38 PM
=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
 
Posts: n/a
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! ]

Reply With Quote
  #6 (permalink)  
Old 08-01-2008, 08:39 PM
sean_in_raleigh@yahoo.com
 
Posts: n/a
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! ]

Reply With Quote
  #7 (permalink)  
Old 08-01-2008, 08:58 PM
Joe Greer
 
Posts: n/a
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! ]

Reply With Quote
  #8 (permalink)  
Old 08-02-2008, 01:19 AM
Bo Persson
 
Posts: n/a
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! ]

Reply With Quote
  #9 (permalink)  
Old 08-02-2008, 01:19 AM
Alberto Ganesh Barbati
 
Posts: n/a
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! ]

Reply With Quote
  #10 (permalink)  
Old 08-02-2008, 01:21 AM
Oncaphillis
 
Posts: n/a
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! ]

Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > C++


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:23 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
MPAA | Secured Loans | Credit Report | Magazine Subscriptions | Myspace Codes



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114