469,631 Members | 1,225 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Beginner post-increment question

The following statement:

line_buf[line_len++] = ' ';
is equivalent to:

line_buf[line_len] = ' ';
line_len++;

because post-increments are done AFTER the non-incremented values are
used in the statement.
Correct?
Jan 15 '08 #1
3 2704
yes, it's correct but note that you should avoid to:

1) use the increment or decrement operators on a variable that appears
more than once in an expression

For example avoid using constructs like the following

n = 1;
y = n++ + n++;

2) use the increment or decrement operators on a variable that is part
of more than one argument of a function

Example to avoid

printf("%d %d\n", number, number*number++);

The reason is because the second argument might be evaluated before
the first one
Jan 15 '08 #2


DiAvOl wrote:
yes, it's correct but note that you should avoid to:

1) use the increment or decrement operators on a variable that appears
more than once in an expression

For example avoid using constructs like the following

n = 1;
y = n++ + n++;

2) use the increment or decrement operators on a variable that is part
of more than one argument of a function

Example to avoid

printf("%d %d\n", number, number*number++);

The reason is because the second argument might be evaluated before
the first one
You forgot the one thing to avoid:

3) Never use pre or post increment as parameters to macros, as a macro
might use the parameter more than once. As a consequence, item 2
should be "never use increment or decrement on parameters to a
function", as you might not know if this is a real function, or that
this was implemented as a macro.

Kind regards,
Johan Borkhuis
Jan 15 '08 #3
Flash Gordon wrote:
>
.... snip ...
>
implementation is *not* free to feed your mother to the
ravenous bug blatter beast of traal.
Ahh. That explains many of my problems. :-)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Jan 16 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Rod Carrol | last post: by
2 posts views Thread by Zipper | last post: by
7 posts views Thread by Rensjuh | last post: by
3 posts views Thread by Chung Hang Shum | last post: by
18 posts views Thread by mitchellpal | last post: by
1 post views Thread by Blue_hatter | last post: by
28 posts views Thread by angeluslii | last post: by
22 posts views Thread by ddg_linux | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.