"Dave Korn" <[EMAIL PROTECTED]> writes:

| On 29 June 2006 14:44, Richard Guenther wrote:
| 
| > But with C language constructs you cannot assume that an object
| > passed to a function via a const pointer is not modified.  So, there
| > is no real "const" regarding to objects pointed to.  Consider
| > 
| > void foo(const int *i)
| > {
| >   int *k = (int *)i;
| >   *k = 0;
| > }
| > int bar(void)
| > {
| >   int i = 1;
| >   foo(&i);
| >   return i;
| > }
| > 
| > should return 0, not 1.
| 
|    That's cheating!  You casted away const, it's a blatant aliasing violation,
| you deserve everything you get.  The compiler is specifically *allowed* to
| assume you don't pull stunts like this *in order to* make const-optimisation
| possible and useful.

Not from the C language point of view.

-- Gaby

Reply via email to