473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Defined bahavior or otherwise?


If the following construct defined behaviour
in the standard?

v += v + x;

(Assuming all variables are of the
same type.)

I know what I would expect the construct
to do, but expected is not necessarily
defined.

--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
Nov 14 '05 #1
14 1528
On Thu, 08 Apr 2004 00:55:35 GMT, Nick Landsberg <hu*****@NOSPAM.att.net>
wrote:

If the following construct defined behaviour
in the standard?

v += v + x;
Since the result cannot vary due to permissible variations in evaluation
order between sequence points (of which there don't seem to be any here),
you should be all set.
(Assuming all variables are of the
same type.)
I'm not sure it would make any difference if they weren't.
-leor
I know what I would expect the construct
to do, but expected is not necessarily
defined.


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #2
Leor Zolman wrote:
On Thu, 08 Apr 2004 00:55:35 GMT, Nick Landsberg <hu*****@NOSPAM.att.net>
wrote:

If the following construct defined behaviour
in the standard?

v += v + x;

Since the result cannot vary due to permissible variations in evaluation
order between sequence points (of which there don't seem to be any here),
you should be all set.
(Assuming all variables are of the
same type.)

I'm not sure it would make any difference if they weren't.
-leor
I know what I would expect the construct
to do, but expected is not necessarily
defined.


Thanks, Leor :)
--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
Nov 14 '05 #3
Leor Zolman <le**@bdsoft.com> spoke thus:
I'm not sure it would make any difference if they weren't.


Well, if one of them is an unsigned short, and the other isn't, then
differences are likely to ensue :)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #4
On Thu, 8 Apr 2004 02:29:42 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.cyberspace.org> wrote:
Leor Zolman <le**@bdsoft.com> spoke thus:
I'm not sure it would make any difference if they weren't.


Well, if one of them is an unsigned short, and the other isn't, then
differences are likely to ensue :)


Well, okay...but as I read it, that would result in
implementation-/defined/ behavior, which would at least remain in the
"defined" category, and thus within the target range of the OP's question
;-)
-leor
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #5
On Thu, 08 Apr 2004 00:55:35 GMT, Nick Landsberg
<hu*****@NOSPAM.att.net> wrote in comp.lang.c:

If the following construct defined behaviour
in the standard?

v += v + x;

(Assuming all variables are of the
same type.)

I know what I would expect the construct
to do, but expected is not necessarily
defined.


If all the variables are of signed or floating point type, there is
always the possibility of undefined behavior if the sum of v and x is
outside the range of the type.

But overflow/underflow aside, the expression if perfectly well
defined. v is modified only once, on the left hand side of the
assignment operator, and the other access to it, on the right hand
side, is used in calculating the new value.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #6
On Thu, 08 Apr 2004 00:55:35 GMT, Nick Landsberg
<hu*****@NOSPAM.att.net> wrote:

If the following construct defined behaviour
in the standard?

v += v + x;

(Assuming all variables are of the
same type.)

I know what I would expect the construct
to do, but expected is not necessarily
defined.


Since this is syntactic sugar for
v = v+v+x;
the behavior of both must be equally defined. Other than pathological
cases of underflow or overflow, why would the question even be raised?
<<Remove the del for email>>
Nov 14 '05 #7
Barry Schwarz <sc******@deloz.net> scribbled the following:
On Thu, 08 Apr 2004 00:55:35 GMT, Nick Landsberg
<hu*****@NOSPAM.att.net> wrote:
If the following construct defined behaviour
in the standard?

v += v + x;

(Assuming all variables are of the
same type.)

I know what I would expect the construct
to do, but expected is not necessarily
defined.
Since this is syntactic sugar for
v = v+v+x;
the behavior of both must be equally defined. Other than pathological
cases of underflow or overflow, why would the question even be raised?


If evaluating v has side effects, the two forms are not equivalent, and
so can hardly be called syntactic sugar.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"A bee could, in effect, gather its junk. Llamas (no poor quadripeds) tune
and vow excitedly zooming."
- JIPsoft
Nov 14 '05 #8
In article
<bq*********************@bgtnsc04-news.ops.worldnet.att.net>,
Nick Landsberg <hu*****@NOSPAM.att.net> wrote:
If the following construct defined behaviour
in the standard?

v += v + x;


Yes. The two exceptions that cause undefined behavior are:

1. Same object modified twice, but v is modified once only.
2. Object modified, and its value is used, but not to determine the
new value. This is not the case, because the old value of v _is_ used to
determine the new value.
Nov 14 '05 #9
Jack Klein wrote:
On Thu, 08 Apr 2004 00:55:35 GMT, Nick Landsberg
<hu*****@NOSPAM.att.net> wrote in comp.lang.c:

If the following construct defined behaviour
in the standard?

v += v + x;

(Assuming all variables are of the
same type.)

I know what I would expect the construct
to do, but expected is not necessarily
defined.

If all the variables are of signed or floating point type, there is
always the possibility of undefined behavior if the sum of v and x is
outside the range of the type.

But overflow/underflow aside, the expression if perfectly well
defined. v is modified only once, on the left hand side of the
assignment operator, and the other access to it, on the right hand
side, is used in calculating the new value.

Thanks, again.

--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
Nov 14 '05 #10
IMHO, such behaviour is far more obnoxious than a TIA at the end of the
initial post.

Dan

In <4L*********************@bgtnsc04-news.ops.worldnet.att.net> Nick Landsberg <hu*****@NOSPAM.att.net> writes:
Jack Klein wrote:
On Thu, 08 Apr 2004 00:55:35 GMT, Nick Landsberg
<hu*****@NOSPAM.att.net> wrote in comp.lang.c:

If the following construct defined behaviour
in the standard?

v += v + x;

(Assuming all variables are of the
same type.)

I know what I would expect the construct
to do, but expected is not necessarily
defined.

If all the variables are of signed or floating point type, there is
always the possibility of undefined behavior if the sum of v and x is
outside the range of the type.

But overflow/underflow aside, the expression if perfectly well
defined. v is modified only once, on the left hand side of the
assignment operator, and the other access to it, on the right hand
side, is used in calculating the new value.

Thanks, again.

--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch

--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #11
On 8 Apr 2004 16:42:28 GMT, Da*****@cern.ch (Dan Pop) wrote:
IMHO, such behaviour is far more obnoxious than a TIA at the end of the
initial post.


If what you're referring to as obnoxious are posts by OPs to say "Thank
you" to their responders, then I'd enthusiastically welcome two instances
of /that/ sort of obnoxiousness for every one of all the other types ;-)
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #12
Leor Zolman wrote:
On 8 Apr 2004 16:42:28 GMT, Da*****@cern.ch (Dan Pop) wrote:

IMHO, such behaviour is far more obnoxious than a TIA at the end of the
initial post.

If what you're referring to as obnoxious are posts by OPs to say "Thank
you" to their responders, then I'd enthusiastically welcome two instances
of /that/ sort of obnoxiousness for every one of all the other types ;-)
-leor


Actually, I owe folks an apology about that.

I replied to the initial response with a thanks,
not realizing that there were other additional
reponses. (I should have scanned the headers.)
After the second one, I should have realized
that there may be others and just limited
it to a single "thanks to all who replied"
rather than "spamming" the NG.

Mea Culpa.

--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
Nov 14 '05 #13
Nick Landsberg wrote:
If the following construct defined behaviour
in the standard?

v += v + x;


This seems a lot trickier:

v = v += x;

;)

I reckon this causes undefined behaviour...

--
Martijn
http://www.sereneconcepts.nl
Nov 14 '05 #14
"Nick Landsberg" <hu*****@NOSPAM.att.net> wrote in message
news:bq*********************@bgtnsc04-news.ops.worldnet.att.net...

If the following construct defined behaviour
in the standard?

v += v + x;

(Assuming all variables are of the
same type.)


If all variablkes are of the same /pointer/ type, then the behaviour is
defined absolutely clearly :-)
Nov 14 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Duncan Bloem | last post by:
Hello, I am not a stylesheet designer, but I am wondering if (and how) the following XML file can be transformed to a custom defined text output file. from XML file: <?xml version="1.0"...
5
by: DJTB | last post by:
Dear Group, I'd like to check if a value is defined in an enum. Example: ------------------------------------------------------ typedef enum { A_VALUE = 1,
14
by: Nick Landsberg | last post by:
If the following construct defined behaviour in the standard? v += v + x; (Assuming all variables are of the same type.) I know what I would expect the construct to do, but expected is...
7
by: William L. Bahn | last post by:
I'm working on some lessons and want to be sure I get some stuff correct. If any of this is covered in the FAQ, please feel free to point me to the section - I couldn't find it. ...
10
by: Axel Dahmen | last post by:
Hi, I want to start a technical discussion on the fact that C# doesn't define any mathematical operators on other integral types than int. Simple things like the following just aren't possible...
6
by: Jody Gelowitz | last post by:
I have run into an issue with variable scope within an XSLT document that is translated in VS.NET 2.0. Under VS.NET 1.1 (XslTransform), this code works fine. However, when using VS.NET 2.0...
4
by: Thelma Roslyn Lubkin | last post by:
I use vector and matrix classes that I developed before they were otherwise easily available. They are template classes that should be able to use objects of other classes I've developed, e.g....
1
by: jason.cipriani | last post by:
Here is an example with 3 files, containing a template structure and also a template function. The header A.h declares a template structure A with a default (i.e. for any template parameter),...
5
by: globalrev | last post by:
if pygame.key.get_pressed: print "Muppet" K_a is not defined. but yes it is. why do i get this error? this works: if pygame.key.get_pressed():
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.