Non-Portable pointer assignment?

Norman Diamond diamond at jit533.swstokyo.dec.com
Fri Jun 7 11:36:05 AEST 1991


In article <MCDANIEL.91Jun6111329 at dolphin.adi.com> mcdaniel at adi.com (Tim McDaniel) writes:

>So why in creation was 'x' ever specified to be int?  Why not char,
>with the usual widening in expressions?

The answer is very ugly.  Some old programs took advantage of being able
to put more than one char in a char constant, since it was really an int.
Anyway, no one ever thought of asking "sizeof" of a char constant because
"sizeof" of a char was always 1 anyway, and no one multiplied by something
they knew was 1.  And outside of "sizeof", you can't distinguish one kind
of integer constant from another.  For example, there's no way of specifying
a short constant.  (Well, you can specify a long, but that's because ints
didn't automatically promote to longs.  And you can now specify unsigned,
but this didn't break any existing code, I think.)

>And why did X3J11 specify that the types of enum constants were int,
>rather than the same type as the underlying enum type?

Actually this is one of the few consistent things around.  For example,
3 is not a char even though it fits in one, and 3 is not a short even
though it fits in one.

If you really want to be horrified, I cannot find any requirement that
an enumeration type actually be able to hold all of the values of its
members.  For example, in
  enum what_type { a = -1, b = 1000000 } what;
well enum what_type might be compatible with unsigned short, and what
might be unable to hold the value of a or b....
--
Norman Diamond       diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
Permission is granted to feel this signature, but not to look at it.



More information about the Comp.std.c mailing list