Re: ANSI C clarifications, with citations (was Re: [patch-2.4
Manfred Spraul (manfred@colorfullife.com)
Tue, 27 Jun 2000 18:23:16 +0200
[cc list trimmed]
"Albert D. Cahalan" wrote:
>
> Larry McVoy writes:
> > Albert D. Cahalan spewed forth:
>
> >> Moderately portable code assumes a sane compiler and sane hardware.
> >> You may assume:
> >>
> >> 1. The "char" type is 8 bits. It might be unsigned though. :-/
> >> 2. sizeof(short) == 2
> >> 3. sizeof(int) == 4 (for real Linux, not the 8088 hack)
> >> 4. sizeof(long) == sizeof(void *)
> >> 5. (sizeof(long) == 4) | (sizeof(long) == 8)
> >> 6. sizeof(long long) == 8 (good for 10 years at least)
> >> 7. You can freely cast between any two pointer types
> >> 8. You can freely cast between long and any pointer type
> >> 9. (long)(int*)(long)foo == (long)(char*)(int*)(long)foo
> >> 10. signed integers are represented in two's complement form
> >> 11. integers wrap around instead of causing faults
> >> 12. assuming "good" struct layout, padding only occurs at the end
> >> 13. ... that padding won't happen if you supply a multiple of 16 bytes
> >
> > Albert, Albert, Albert. You never cease to amaze me.
> >
> > Let's dissect your message a bit, shall we?
>
> Sure, but in fairness I must rip apart your silly rant.
>
> Note that the kernel makes EVERY ONE of the above assumptions.
> The kernel even assumes a stricter version of #13, and it assumes
> that you have big-endian or little-endian hardware.
>
I'm a bit concerned about 6. and 13.
6. sizeof(long long) == 8.
>=8 would be better, which code assumes ==8?
13. Perhaps someone decides that alignment should be extended to the
cache line size.
(a 48 byte structure is padded to 64 bytes)
--
Manfred
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/