S
Srini
Pardon me if this is trivial.
I think I read somewhere that statements like this cause undefined
behavior.
int n = n;
How is the above statement different from
int n(n);
This above statement gives an error saying that 'n' is undeclared. I
saw the assembly listing for this following piece of code. Using g++
3.3.3
int x = 10;
int n = x;
int m(x);
The assembly listing was something like this...
movl $10, -4(%ebp)
movl -4(%ebp), %eax
movl %eax, -8(%ebp)
movl -4(%ebp), %eax
movl %eax, -12(%ebp)
I see that for both of these, the assembly code generated is the same.
May be its different for class objects. This whole thing brings doubts
in my mind whether I must check for self initialization in copy
constructors. Please share your thoughts on this.
Regards,
Srini
I think I read somewhere that statements like this cause undefined
behavior.
int n = n;
How is the above statement different from
int n(n);
This above statement gives an error saying that 'n' is undeclared. I
saw the assembly listing for this following piece of code. Using g++
3.3.3
int x = 10;
int n = x;
int m(x);
The assembly listing was something like this...
movl $10, -4(%ebp)
movl -4(%ebp), %eax
movl %eax, -8(%ebp)
movl -4(%ebp), %eax
movl %eax, -12(%ebp)
I see that for both of these, the assembly code generated is the same.
May be its different for class objects. This whole thing brings doubts
in my mind whether I must check for self initialization in copy
constructors. Please share your thoughts on this.
Regards,
Srini