A
Alexander Bartolich
begin tinybyte:
It is not changed by magic but by your request.
Using an explicit cast. You asked for trouble, you got trouble.
If you fix this line
ip = (int *) #
to
ip = #
you should get a diagnostic similar to
warning: assignment discards qualifiers from pointer target type
If you change the declaration to
const int *ip;
then the diagnostic will change to
warning: assignment of read-only location
C gives you enough rope to hang yourself.
And then a couple of more feet, just to be sure.
Always has been, always will be.
There are indeed languages out there that protect the code from
hostile programmers, e.g. Smalltalk, Java, C#, Python, Ruby.
If you want that, go for it.
The compiler is allowed to assume that the value it's not changed,
but sometimes it is changed, sometimes not, depends on optimization.
It is not changed by magic but by your request.
Using an explicit cast. You asked for trouble, you got trouble.
If you fix this line
ip = (int *) #
to
ip = #
you should get a diagnostic similar to
warning: assignment discards qualifiers from pointer target type
If you change the declaration to
const int *ip;
then the diagnostic will change to
warning: assignment of read-only location
This is inconsistent behavior for me, and in C programming this
should not be ALLOWED.
C gives you enough rope to hang yourself.
And then a couple of more feet, just to be sure.
Always has been, always will be.
[...] A value that cannot be changed has been changed, under
certain conditions. That means something is broken.
There are indeed languages out there that protect the code from
hostile programmers, e.g. Smalltalk, Java, C#, Python, Ruby.
If you want that, go for it.