Compiler accepting invalid keywords!

Started by
6 comments, last by PolyVox 21 years, 1 month ago
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
Advertisement
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....)
Ok, great! That saves me a lot of work... Can someone tell me if the microsoft compilers support them?
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?
MSVC 6 and .NET play happily with them if you include iso646.h .
Borland C/C++ v5.1 for MS Windows dont like it.
This trick helps:
#ifndef and
#define and &
#endif
"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We WouldWhen Losers Say Its Over With You Know That It's A Lie The Gods Made Heavy Metal And It's Never Gonna Die"THE GODS MADE HEAVY METAL/by ManOwaR
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]
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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement