Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Would this cause undefined behavior please?

Reply
Thread Tools

Would this cause undefined behavior please?

 
 
rayw
Guest
Posts: n/a
 
      08-18-2008
int x,y,z;

x=y=z=1;

z=++x||++y && ++z;

My understanding is that the order of things here are:

++x = x = 2

As x is 'true', the ++y doesn't operate

To evaluate &&, ++z operates, setting z to 2.

true && true, and that assigns 1 to z.

Is this right please?
 
Reply With Quote
 
 
 
 
rayw
Guest
Posts: n/a
 
      08-18-2008

> * * *z=++x||++y && ++z;
> means the same thing as:
> * * *z = ++x || (++y && ++z);
>
> To evaluate the result of the || operator,
> (++x) is evaluated first, like you said,
> but after that, there is nothing more to do.
>
> (++y && ++z) is not evaluated.


Of course! Many thanks.
 
Reply With Quote
 
 
 
 
lawrence.jones@siemens.com
Guest
Posts: n/a
 
      08-22-2008
pete <> wrote:
>
> (++y && ++z) is not evaluated.


Which is good because, if it were, you (the OP, not pete) would be
trying to set the value of z twice in the same expression without a
sequence point between them, which is undefined behavior, just like:

z = ++z;
--
Larry Jones

I just can't identify with that kind of work ethic. -- Calvin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does integer over flow cause undefined behaviour ? dragoncoder C++ 33 05-23-2006 10:46 AM
How likely is a function starting with an underscore to cause undefined behavior? Jim Langston C++ 16 03-22-2006 06:54 AM
will all these messages cause a problem . I am a new subscriber and my computer is downloading 100,000 messages. Will this cause any kind of a problem with my ability to store other items?? Camille White Camille White Computer Support 9 11-08-2004 01:13 AM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM
Does this cause undefined behaviour? ozbear C Programming 14 12-31-2003 09:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57