Jump to content
  • Advertisement

Archived

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

quant

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

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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 this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!