UB / sequence points (was Re: Qry : Behaviour of fgets -- ?)
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > UB / sequence points (was Re: Qry : Behaviour of fgets -- ?)




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    UB / sequence points (was Re: Qry : Behaviour of fgets -- ?)  
Kenneth Brody


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-10-07 06:16 PM

Rainer Weikusat wrote:
>
> rlb@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...] 
>
> It is not (generally) possible to execute microprocessor instructions
> which don't do something specific. But this speculation is besides the
> point. The bheaviours is undefined. This means it is undefined.

You've never run on a CPU which can perform more than one
instruction at a time, have you?

Consider, for example:

int i;
..
i = i++;

There is no reason to expect that the compiler can't generate
something along the lines of:

something   \ These two instructions run in parallel
load  r1,i  /

store r1,i  \ As do these
incr  i     /

This isn't an issue with "j = i++" because the store will write
to j.  However, in this case, both instructions attempt to write
to i, causing a bus conflict and locking the system.

Perhaps the system has some protection against this, but it will
still fail depending on the value in i.  Perhaps, for example, if
i is 0xffffffff and the increment causes an overflow exception to
occur while it is handling the collision exception.

Okay, I suppose you could say that this behavior is "defined" in
the sense that the outcome is not dependent on quamtum physics,
but it's still not "defined" in the sense that "the answer must
be A or B".  (There are many people who stongly believe that the
only possible outcome of "i=3; i=i++;" is that i must contain the
value 3, and there are others who know about sequence points who
will insist that the only possible answers are that i contain the
value 3 or 4.)

And, regardless, the behavior is still "undefined" as far as the
C standard is concerned.  Code that depends on a particular
compiler's particular code generator's output is asking for
trouble.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody        | www.hvcomputer.com | #include              |
| kenbrody/at\spamcop.net | www.fptech.com     |    <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@gmail.com>







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:03 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register