#### Archived

This topic is now archived and is closed to further replies.

# Compiler accepting invalid keywords!

This topic is 5396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have an interesting problem in that my program compiles when I''m not sure it should! I''ve been using the keywords ''or'' and ''and'' in C++, but it''s just come to my attention they may not be valid! I am working under Redhat Linux 8.0, and the text editor KATE highlights them as keywords. GCC 3.2 also seems happy to accept them. But other people have reported being unable to compile my software as a result! I can''t actually find any mention of them being legal. So can someone tell me if they are legal, and if not how can I prevent GCC accepting them? The -ansi flag does not appear to work. Cheers, David

##### Share on other sites
They are part of standard C++ (Section 2.5 - Alternative tokens in the standard).

(Though technically they aren''t keywords - I believe they''re called reserved identifiers, which is sort of like being the ugly stepbrother of a keyword.)

If you''re having trouble with other compilers not accepting your code, try including iso646.h at the top of your source files. It defines macros to replace and, or, etc. with the actual &&, ||, etc. (Of course if the compiler doesn''t recognize the identifiers, it''s probably old enough to not have shipped with all the standard headers....)

##### Share on other sites
Ok, great! That saves me a lot of work... Can someone tell me if the microsoft compilers support them?

##### Share on other sites
I am using .NET, and it doesn''t like them.

I am also using gcc version 2.95.3 (from SN Systems) and it doesn''t seem to like them either. Do you know what version of gcc added that support?

##### Share on other sites
MSVC 6 and .NET play happily with them if you include iso646.h .

##### Share on other sites
Borland C/C++ v5.1 for MS Windows dont like it.
This trick helps:
#ifndef and
#define and &
#endif

##### Share on other sites
quote:
Original post by chiuyan
I am also using gcc version 2.95.3 (from SN Systems) and it doesn't seem to like them either. Do you know what version of gcc added that support?

I'd guess that the 3.x series (3.2.x is the current series, and "and" works fine) added support if 2.95.x doesn't have it (it doesn't seem to, I tested GCC 2.95.4 too). I haven't taken the time to try to look this up though. Edit: fixed omited text.

[edited by - Null and Void on March 7, 2003 4:48:48 AM]

##### Share on other sites
quote:
Original post by Estor
Borland C/C++ v5.1 for MS Windows dont like it.
This trick helps:
#ifndef and
#define and &
#endif

#define and &&#define bit_and &

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

• ### Forum Statistics

• Total Topics
628686
• Total Posts
2984234

• 16
• 13
• 13
• 10
• 10