However I am ALSO correct :)) That is because the rules are
entirely characterized in terms of alignment requirements.
If the alignments of float32 and uint32 are the same, the above
must work.
No. C is a cruel language that few people really understand.
True. Including the committee members ;(
We can discuss the “restrict” keyword if you’d like your brain
to melt and pour out of your nose.
Lol! No thanks. WG14 tried noalias first … but that didn’t
pan out.
Other good ones are
"const" (which isn’t) and “volatile”. We need a C-- language.
We have a C-- language.
Anyway…
I’m not kidding on this.
Neither am I
You are of course correct that you cannot use a value via
an alias which is of a type incompatible with the value
actually stored.
however that is not an aliasing rule: the same rule forbids
using an uninitialised value.
Aliases of ANY types are in fact allowed: see ISO C99 6.3.2.3/1,
which says pointers to any incomplete or object type can be converted
to or from void*. Combining the two cases one deduces any such pointer
can be converted to any other.
This ability to alias any object types is obvious anyhow,
since you can put any object types in a union to create an alias.
In the example code you ARE correct that there must be a misuse
of an alias, but your argument that types cannot be aliased is
incorrect. IMHO. Since interpreting the C Standard is difficult
In a slightly more difficult example, we examine lvalues
which are assignment targets. In that case there is no abuse
of a wrongly typed value, however we may STILL want to ban
such an operation.
The thing is, objects do not have a type, only value
representations. But storage does have alignment and size.
So the only way to ban storing a float in an int, is to make
sure that they have either different sizes or different alignments.
In this case, we will choose the following alignments:
float32 --> SSE
int32 --> EiX
least upper bound (SSE, EiX) --> 4
no one said alignments had to be integers, nor that the ordering
had to be linear – actually, it has to form a lattice I think,
with alignof unsigned char* being the minimum, and some alignment which
malloc provides being the maximum – pity that one isn’t named,
I need it often.
The C standard really is that evil.
Yup. But it is standardising an evil language, what do
you expect?
In case you’re wondering, the C standard is like this so that
compilers can optimize better.
I’m afraid that isn’t a good account of the process ;(
The standards committee
likes to support stuff like the AS/400, where you’d actually
get a fault/exception/crash for touching memory of the
wrong type. The committee also cares about trying to keep
up with FORTRAN performance. The screwball DSP vendors
are pretty well represented too. No care is given to the fact
that all normal systems (server, desktop, PDA, cellphone)
use normal 32-bit IEEE float, etc.
That isn’t quite fair. Support for weird platforms is important,
because in the future someone may invent nice ones!
I’d complain the other way – C99 actually adds gratuitous
overconstraints on integer types, and fails to add some
others that are vital. The C Standard (and that of C++) is a result
of a political process. I’d have to say … looking at the political
leaders of various countries over time … the standards committees
are doing quite well
“Doctor, it hurts when I C things”
"Then don’t C things"On Tue, 2006-02-14 at 01:53 -0500, Albert Cahalan wrote:
–
John Skaller
Felix, successor to C++: http://felix.sf.net