T
thamizh.veriyan
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.
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.