 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Sat May 12, 2007 9:10 am Post subject: Trap representations producing Undefined Behavior |
|
|
Hi,
I am new to this community. I have a doubt regarding trap
representations.
I read in IBM's website that something like this is legal:
int main(){
int x=3;
{
int x=x;
}
}
It said there that the scope of x in the inner block begins after the
initialization. So during the initialization process, the latter x in
"int x=x" refers to x in the outer scope. I understood that to an
extent.
But someone told me that something like this can produce Undefined
Behavior:
int main(){
int x=3;
{
int x=x++;
}
}
Why does this code snippet exhibit Undefined Behavior? I was told that
here x++ can prduce trap representation. I wasnt able to understand
that. According to me, the x++ refers to x in the outer scope. So why
can't this return the current value of x (in the outer scope) i.e. 3
and also increment it?
I was also told that something like this is well defined.
int main() {
struct X {X operator++(int) {return X();} } x;
x=x++;
}
Can you please explain how?
Am sorry about asking so many questions. I thought they are all
related and decided to ask them here. Please forgive me if you think
they are not related. I would be grateful if you could help me
understand this better. Thanks. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|