Reputation: 19721
In C++, we can write and
for &&
, or
for ||
, bitand
for &
and bitor
for |
.
Now I wonder whether and
and bitand
are only valid where those operators are meant, or also where references are defined (g++ 4.6.3 accepts bitand
for references — rvalue references seem not to be supported in that version — but of course that might just be the compiler not catching the error).
In short: Is the following code valid C++?
int and x = 3;
int a;
int bitand y = a;
Of course I would never write such code (except maybe if participating in an obfuscated code contest), but is it actually valid?
Upvotes: 9
Views: 421
Reputation: 477000
According to C++11, 2.6/4:
In all respects of the language, each alternative token behaves the same, respectively, as its primary token
So int and a = 5;
is perfectly valid, though also perfectly insane.
More examples:
struct ete
{
compl ete();
int egr()and;
};
Upvotes: 11