473,398 Members | 2,088 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,398 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 1532
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.