On Wednesday 25 April 2007 17:17, Ian Lance Taylor wrote: > Marco Manfredini <mldb@xxxxxxx> writes: > Unfortunately a const pointer in C/C++ doesn't mean "the value this > points to can not change." It only means "the value this points to > can not be changed via this pointer." So there is no way to express > what you want in the standard language. Nor does gcc provide an > extension along these lines. I hoped there was an __attribute__((const)) for function parameters somewhere in the hide. > > gcc does provide the extension of annotating fun with __attribute__ > ((pure)). If fun is indeed a pure function, then gcc might be perform > the optimization you want. I haven't tried. Of course, if fun is not > pure, that won't help. pure doesn't help, yes. It isn't even available for my x86_64 target. What I thought of was some clever hack which tricks the compiler into thinking that a completely new pointer had appeared. I've tried: const val* __attribute__((malloc)) summon_pointer(const val *p) { return p; } but with no luck. If the task is to create a new pointer for which the compiler can't see the relation to the original, then __asm__ abuse would be my next idea, but I don't have a clue how to twiddle the constraints for this case. Marco