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

Regarding behavior of code:

See the following code snippet:

{
int a=1;
printf("%d %d %d",a,++a,a++);
}

Will the behavior be undefined/unspecifed or no such thing? Please
state reasons, along with your post(s).
Oct 11 '08 #1
3 1230
co**************@gmail.com said:
See the following code snippet:

{
int a=1;
printf("%d %d %d",a,++a,a++);
}

Will the behavior be undefined/unspecifed or no such thing?
Undefined.
Please state reasons, along with your post(s).
Same reason it was undefined the other eight million times it was asked.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 11 '08 #2
On Oct 11, 12:02*pm, Richard Heathfield <r...@see.sig.invalidwrote:
coolguyaround...@gmail.com said:
See the following code snippet:
{
int a=1;
printf("%d %d %d",a,++a,a++);
}
Will the behavior be undefined/unspecifed or no such thing?

Undefined.
Please state reasons, along with your post(s).

Same reason it was undefined the other eight million times it was asked.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Why do you say undefined and not unspecified?
Oct 11 '08 #3
co**************@gmail.com said:
On Oct 11, 12:02 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>coolguyaround...@gmail.com said:
See the following code snippet:
{
int a=1;
printf("%d %d %d",a,++a,a++);
}
Will the behavior be undefined/unspecifed or no such thing?

Undefined.
Please state reasons, along with your post(s).

Same reason it was undefined the other eight million times it was asked.
Why do you say undefined and not unspecified?
Same reason it was undefined the other eight million times it was asked.
Quoth the Standard: "Between the previous and next sequence point an
object shall have its stored value modified at most once by the evaluation
of an expression. Furthermore, the prior value shall be accessed only to
determine the value to be stored."

Note the uses of the word "shall". And these are "shall"s that are not part
of a constraint.

"In this Standard, ``shall'' is to be interpreted as a requirement
on an implementation or on a program; conversely, ``shall not'' is to
be interpreted as a prohibition."

"If a ``shall'' or ``shall not'' requirement that appears outside of a
constraint is violated, the behavior is undefined."

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 11 '08 #4

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

Similar topics

17
by: matthias_k | last post by:
Hi, I am currently implementing a solver for linear optimization problems using the revised simplex method and I stumbled accross some strange behavior regarding the treatment of the number 0....
3
by: Karl M | last post by:
Hi everyone, I just notice some strange behaviors on the MS C++ compiler regarding struct default constructor, see the example bellow: struct MyStruct { int a; }; class MyClass { public:
4
by: duffdevice | last post by:
Hi, I came across this unexpected behavior while working on something else. I am attempting to return a custom type by value from a global function. I have a trace in the custom class's copy...
20
by: sam_cit | last post by:
Hi Everyone, I have the following code, int main() { int p = {10,20,30,40,50}; int *i = &p; printf("before : %p\n",(void*)i); printf("1 %d %d\n",*++i,*i++);
6
by: wizwx | last post by:
Is there anything wrong with the following code? class A { ... }; class B : public A { ... }; // definitions of class A and B, these are OK Foo() { A & a = B(); // ?? A * p = &B(); // ??...
17
by: venkat | last post by:
Hi, I have written a program void main() { printf("%d %d\n", sizeof main, sizeof(main())); } in this program the output is 1 and 4,
8
by: somenath | last post by:
Hi All, I have a doubt regarding the pointer assignment . Please have a look at the following program . #include<stdio.h> #include<stdlib.h> #define NAMESIZE 10 #define SAFE_FREE(t) if(t)\...
2
by: Pinux | last post by:
Hi, I now run into a very strange behavior when using ifstream. Can anyone please help me out here: Basically, what I want to do is to encrypt a plain text file into a cipher text and then...
5
by: Philip Potter | last post by:
I have a somewhat flippant question regarding undefined behaviour. Does an operation which invokes undefined behaviour affect the whole program, or are earlier statements guaranteed to execute...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.