piclist 2008\07\23\165159a >
Thread: What to do about compiler bug and source code?
picon face BY : Tomás Ó hÉilidheemail (remove spam text)

William "Chops" Westfield wrote:
> That's not the problem.  The problem is whether the left side or  
> right side of the assignment is evaluated first.  (actually, I think  
> it would be a problem even if it was a comparison rather than an  
> assignment.)

Yes you're right, you'll get this problem in places where the following
two criteria are satisfied:
   * There is no sequence point between the two things that need to be
   * The order of evaluation is "unspecified"

> It tends to annoy me that compiler standards writers can leave  
> something relatively important like this out of their specs, while  
> getting all pissy about some obscure corner.

I believe it was deliberately left out to aid in code optimisation. For
instance, if you had a line of code such as the following:

   some_variable = Func1() + Func2() * Func(3) / Func(4);

then the compiler can call the functions in whatever order it pleases.
Supposedly this gives the compiler the freedom to produce the most
efficient machine code it can. If you wanted definitive order, you'd
need to do introduce a "sequence point", maybe like as follows:

   some_variable = Func1();
   some_variable += Func2();
   some_variable *= Func3();
   some_variable /= Func4();

For those who don't know and are wondering, a sequence point is sort of
like a "fullstop". When you reach a sequence point, everything before it
must finish being evaluated before anything after it can be evaluated.
The Standard gives a finite list of when and where a sequence point
occurs; the most common one you'll be familiar with is the semi-colon at
the end of a statement.

> It REALLY annoys me when compiler writers use the lack of  
> specification to arbitrarily change behavior from one version to the  
> next.  (I didn't see that with this particular issues, but we got  
> bitten pretty hard on a change in pre-processor operation ordering  
> between gcc2.95 and gcc3.4...)  Grr.

I suppose the only thing you can say about it is that people should
learn this stuff from the very start. The book I used for learning C was
"C++ for Dummies" (I actually started out learning C++ before I delved
into C), and very early on in the book it explained about how the order
of evaluation can be arbitrarily chosen by the compiler.

Actually this makes me think of something... it would be great to have a
tool that would scan through code looking for instances in which code
will behave differently on different systems because of unspecified
behaviour. It wouldn't even need to compile the code, it would just spit
out something like:
   Warning: The statement on line 3 can have more than one effect on
different platforms

I've heard of something called Lint, only heard of it, never used it,
but I don't think it goes into this detail. I might start a thread on
comp.lang.c and see what the lads think.

<488799CD.6070103@lavabit.com> 7bit

In reply to: <9418F12D-B78B-4BEF-9225-01B5BD12A717@mac.com>
See also: www.piclist.com/techref/index.htm?key=what+about+compiler
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) What to do about compiler bug and source code?

month overview.

new search...