An example of unions not being type safe?

M

Mark McIntyre

No, it is actually implementation-defined in C90. The fact that the C90
Standard states it is implementation-defined means that it is
implementation-defined in the C90 Standard. If the ISO C Committee
decide that it constitutes a defect in that Standard, they can issue a
TC - and presumably they did. But that doesn't affect the C90 Standard.
It only affects a Standard that we might reasonably call "C90 + TCs 1
to n", where n is the number of the TC in which the correction was
made.

Come now, this is just silly. If a corrigendum is issued, it corrects
the original document. This is no different to if any text book is
corrected.

You could however reasonably have claimed that the first N printings
of the standard erroneously listed it as implementation-defined.
Not even the ISO C Committee can change the past.

No, but they can correct mistakes.

I'm detecting a faint whiff of "oops, I didn't realise that but I'm
not going to back down" here. I'm probably mistaken tho.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
K

Keith Thompson

No, I would say that casts aren't type-safe. Casts and unions are two
of the ways to have objects treated as the wrong type.

Not all casts are type-unsafe. A cast specifies a *conversion*; it
doesn't generally interpret an object of one type as if it were an
object of another type.

Pointer casts are potentially type-unsafe. Numeric casts merely
convert values.
 
J

Joe Wright

Keith said:
(e-mail address removed) (Richard Tobin) writes: [ snip ]
No, I would say that casts aren't type-safe. Casts and unions are two
of the ways to have objects treated as the wrong type.

Not all casts are type-unsafe. A cast specifies a *conversion*; it
doesn't generally interpret an object of one type as if it were an
object of another type.
A cast is an explicit conversion of a value from one type to another,
preserving value where possible. It has nothing to do with objects at all.
 
R

Richard Tobin

No, I would say that casts aren't type-safe. Casts and unions are two
of the ways to have objects treated as the wrong type.
[/QUOTE]
Not all casts are type-unsafe.

True, but the point is that in the code above it is the cast that
violates type-safety, not the int as (rhetorically) suggested.

-- Richard
 
K

Keith Thompson

Joe Wright said:
Keith said:
(e-mail address removed) (Richard Tobin) writes: [ snip ]
No, I would say that casts aren't type-safe. Casts and unions are two
of the ways to have objects treated as the wrong type.
Not all casts are type-unsafe. A cast specifies a *conversion*; it
doesn't generally interpret an object of one type as if it were an
object of another type.
A cast is an explicit conversion of a value from one type to another,
preserving value where possible. It has nothing to do with objects at
all.

Right, drop the word "generally" above.

Even pointer casts aren't *directly* type-unsafe, but they enable you
to do type-unsafe things with the results.
 
K

Keith Thompson

Not all casts are type-unsafe.

True, but the point is that in the code above it is the cast that
violates type-safety, not the int as (rhetorically) suggested.[/QUOTE]

Agreed.

Just to pound once more on the greasy spot on the ground that was once
a dead horse :cool:}, I was responding to the "casts aren't type-safe"
remark, which seemed overly general.
 

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top