473,320 Members | 1,900 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,320 software developers and data experts.

side effects

does i++ have the same potential for side effects as its pre-fix
equivilent ++i? and if so, is it always dangerous to use them, as in a
for loop, or only in certain circumstances?

May 14 '06 #1
4 1523
andrew browning wrote:
does i++ have the same potential for side effects as its pre-fix
equivilent ++i? and if so, is it always dangerous to use them, as in a
for loop, or only in certain circumstances?


Define "potential for side effects". Both ++i and i++ will increment i,
if that is what you are asking (or in the case of class types, call the
corresponding version of operator++).

Also, specify what you mean by "dangerous to use them". It is quite
common for increment operators to be used in for loops:
for (unsigned i = 0; i < 10; ++i) { // Do something }

The only dangerous use I can think of is trying to use an increment
operator in an expression where the operand is also being used for
something else:
i = ++i + 1; // unspecified behavior
j = i + i++; // unspecified behavior
j = i++ + ++i; // unspecified behavior

Also, since it inevitably will come up:
http://www.parashift.com/c++-faq-lit...html#faq-13.15

--
Alan Johnson
May 14 '06 #2
* andrew browning:
does i++ have the same potential for side effects as its pre-fix
equivilent ++i?
No, i++ is more side effect oriented than ++i because i++ has only one
reason for existence: producing a side effect in an expression.

i++ can be regarded as (temp = i, ++i, temp).

and if so, is it always dangerous to use them
No.

as in a for loop, or only in certain circumstances?


No. But prefer ++i. That way you tell the reader that you're not
interested in the side effect, and it can be more efficient.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 14 '06 #3
got it.

am i too take it that i'm breaking usenet protocol somehow? i hope i
am not:(

May 14 '06 #4
* andrew browning:
got it.

am i too take it that i'm breaking usenet protocol somehow? i hope i
am not:(


Well, now you are, because you forgot to quote what you responded to.
But originally you were not. Heh. :-)

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 14 '06 #5

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

Similar topics

3
by: Sensorflo | last post by:
After browsing though many newsgroups articels I'm still not shure how operator precedence, operator associativity, sequence points, side effects go together. Currently I have the following view: ...
13
by: Steve Jorgensen | last post by:
== On Error Resume next, and Err.Number == If you want to call one of your procedures from another procedure, and check for errors afterward, you mayimagine that you should write code something...
23
by: Mantorok Redgormor | last post by:
Can emulation of the logical OR be done in standard C to obfuscate its use? So I don't have to use if(a||b) but instead make that even more obfuscated without its use but testing the same condition
9
by: Rouben Rostamian | last post by:
Consider the following illustrative program: #include <stdio.h> double f(double x) { return x*x; } double g(double x)
13
by: Mantorok Redgormor | last post by:
does volatile really inhibit side effects? that is the rules for sequence points and side effects do not apply to volatile objects? -- nethlek
5
by: Niklaus | last post by:
This is one of the posts that i got. ------------------------------ A "side effect" of an operation is something that *happens*, not something that *is produced*. Examples: In the expression...
17
by: dingoatemydonut | last post by:
The C99 standard states: "In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce...
6
by: Senthil | last post by:
Hi, Whenever i read a C++ book or a newsgroup posting, i come across the terms like " before the side effects completes" , "destructor with side effects" etc. What is this side effect mean in C++...
4
by: Academia | last post by:
I get the following watch message: tsSource.Text.ToUpper() This expression causes side effects and will not be evaluated string The Text is &Edit
10
by: mirandacascade | last post by:
Question toward the bottom of this post....background information immediately below. Access 97 SQL Server 2000 Please note: although the subject line uses the word 'bloat', this post is NOT...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
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...

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.