if ( Boolean_A & = 0x0020 )
legal? Specifically, should the three-character sequence "& =" be
treated as representing the two-character operator "&="?
As I understand the standard (ISO section 5.1.1.2, phase 7), the "&"
is converted into one token, and the "=" is converted into another.
This then precludes treating them as one operator, and the program
fragment is illegal.
However, a compiler I respect instead treats this as a legal fragment
involving the "&=" operator. Is that allowed? (The program fragment
was caused by a bad macro definition. If the compiler had complained,
we would have found the problem earlier.)
--
Richard Smiley (317) 451-0866 c2x...@eng.delcoelect.com
Assuming this is in the main C language (i.e. after preprocessing has been
done, and not inside a string literal or anything), I think that any program
containing the three-character sequence "& =" must have a syntax error.
Every conforming implementation must issue a diagnostic.
>However, a compiler I respect instead treats this as a legal fragment
>involving the "&=" operator. Is that allowed? (The program fragment
>was caused by a bad macro definition. If the compiler had complained,
>we would have found the problem earlier.)
In addition to issuing a diagnostic, the implementation is free to do
whatever else it likes, such as pretending it was the two-character
operator "&=". Furthermore, the diagnostic doesn't have to be accurate or
meaningful. If the implementation issues any diagnostic at all, for example
a warning about some other part of the program, or a warning saying that
the implementation doesn't try very hard, then it meets the requirement.
If the implementation issued no diagnostic at all about your program,
and if you invoked the implementation according to the vendor's instructions
for a conforming implementation, then I'd say you're entitled to a refund.
In any case, you can consider not buying anything further from that vendor.
The marketplace speaks louder than the standard, and on rare occasions
quality speaks too.
--
<< If this were the company's opinion, I would not be allowed to post it. >>
"I paid money for this car, I pay taxes for vehicle registration and a driver's
license, so I can drive in any lane I want, and no innocent victim gets to call
the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
No to both questions.
> As I understand the standard (ISO section 5.1.1.2, phase 7), the "&"
> is converted into one token, and the "=" is converted into another.
> This then precludes treating them as one operator, and the program
> fragment is illegal.
Correct.
> However, a compiler I respect instead treats this as a legal fragment
> involving the "&=" operator.
This is permitted, provided at least one diagnostic is produced along
the way.
> (The program fragment
> was caused by a bad macro definition. If the compiler had complained,
> we would have found the problem earlier.)
The &= must exist before the preprocessor works - it can't be generated
by, for example:
#define EQ =
... &EQ
unless you use the ## preprocessor operator, which generates new
tokens.
--
Clive D.W. Feather | If you lie to the compiler,
cd...@cityscape.co.uk (work, preferred) | it will get its revenge.
cl...@stdc.demon.co.uk (home) | - Henry Spencer