Archived

This topic is now archived and is closed to further replies.

Is *i++; a valid ISO/ANSI c++ statement?

This topic is 5718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

n/a

Share on other sites
With an expression so simple, I can''t think of any rules or guidelines it would break.

Share on other sites
Well its sort of like the i++++; statement. Using 2 operations before a ;. And i know i++++ is undefined in the standard. So i was wondering if *i++; is.

Share on other sites
In both cases it depends entirely on the type of i. Note that i++++; is not undefined, but it will usually not be a valid statement (it can be) simply because i++++ will usually not be a valid expression.

Yes.

Share on other sites
quote:
Original post by spock
In both cases it depends entirely on the type of i.

It doesn''t matter. *i++ is valid syntax. The OP gave no context, so guessing at the semantics of his code is a waste of time.
quote:

Note that i++++; is not undefined

It''s undefined because it modifies a variable more than once without an intervening sequence point.

ok thx sabre

Share on other sites
quote:
Original post by SabreMan
It''s undefined because it modifies a variable more than once without an intervening sequence point.

Isn''t it because the post-increment operator returns a rvalue, and not a reference to the variable (lvalue), required for the second post-increment? Pre-increment can be applied twice because it does return an lvalue...

Cédric

Share on other sites
quote:
Original post by SabreMan
*i++ is valid syntax. The OP gave no context, so guessing at the semantics of his code is a waste of time.

Valid syntax is not enough for an expression to be valid, at least not in C++. If you break the rules for valid expressions and statements you end up with an illformed program that won''t compile.

quote:
It''s undefined because it modifies a variable more than once without an intervening sequence point.

It''s defined - as in explicitly or implicitly specified by the standard - for any reasonable i. The expression i++++ could, but does not necessarily, specify rvalue modification in which case it''s defined to not be valid.

Maybe you meant that the behaviour is not defined, but that''s meaningless because behaviour only exist for valid code anyway (if it can''t be compiled it obviously can''t run).

Share on other sites
quote:
Original post by spock
Valid syntax is not enough for an expression to be valid, at least not in C++.

The OP asked is it a valid C+ statement. It is.

1. 1
2. 2
Rutin
20
3. 3
A4L
15
4. 4
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633738
• Total Posts
3013617
×