Liste des Groupes | Revenir à cl c |
Ben Bacarisse <ben@bsb.me.uk> writes:
... Modifying an object whose type is const qualified>
is undefined, even if the object is in writable storage. A compiler
may assume that such an object has not changed because in a program
that has undefined behaviour, all bets are off. [...]
We need to be careful about what is being asserted here. There
are cases where a compiler may not assume that a const object
has not changed, despite the rule that assigning to a const
object is undefined behavior:
>
#include <stdio.h>
typedef union { const int foo; int bas; } Foobas;
>
int
main(){
Foobas fb = { 0 };
>
printf( " fb.foo is %d\n", fb.foo );
fb.bas = 7;
printf( " fb.foo is %d\n", fb.foo );
return 0;
}
>
The object fb.foo is indeed a const object, but an access of
fb.foo must not assume that it retains its original value after
the assignment to fb.bas.
Les messages affichés proviennent d'usenet.