Linux-kernel mailing list archive 2000-26,: Re: ANSI C clarifications, with citations (was Re: [patch-2.4

# Re: ANSI C clarifications, with citations (was Re: [patch-2.4

Sandy Harris (sandy@storm.ca)
Tue, 27 Jun 2000 12:05:23 -0400

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: James Tunnicliffe: "2.4.0-test2 default config problem"
- Previous message: Amit Dror: "vmalloc() in interrupt context"

Rusty Russell wrote:
>
> In message <200006270409.VAA32165@work.bitmover.com> you write:
> > > 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
> >
> > Huh? There are lots of machines for which one or more of these
> > things are not true and #8 is amazing in it's shortsightedness.
>
> Larry, sorry to disappoint. Albert's full list fairly closely
> corresponds with existing kernel assumptions. Attacking the messenger
> won't change this;

Perhaps, but he presented it as "Moderately portable code assumes a
sane compiler and sane hardware." That is a very different thing
than describing current kernel assumptions.

I don't doubt those assumptions are (at least close to) a good
description of what the kernel code currently assumes. On the
other, as a basis for portable code design, Larry's quite right.
Some of them are awful.

Likely some of them are the reason we see elsewhere in the thread:

| Yes, but these assumptions are one of Linux's remaining problems. Code
| which is based on them will not be portable to other arches. But since
| noone cares about them anyway, we might as well declare Linux i386 only,
| it would at least stop the BSD people laughing because our "stable" kernel
| doesn't compile on all "supported" archs.
|
| Simon (running 2.0.36/m68k)

The blurb of Henry's which Larry quoted has a more recent
"annotated edition":

http://lalaland.msu.edu/~vanhoose/humor/0010.html

Its version of the 10th is:

10 Thou shalt foreswear, renounce, and abjure the vile
heresy which claimeth that ``All the world's a VAX'',
and have no commerce with the benighted heathens who
cling to this barbarous belief, that the days of thy
program may be long even though the days of thy current
machine be short.

This particular heresy bids fair to
be replaced by ``All the world's a
Sun'' or ``All the world's a 386''
(this latter being a particularly
revolting invention of Satan), but
the words apply to all such without
limitation. Beware, in particular,
of the subtle and terrible ``All
the world's a 32-bit machine'',
which is almost true today but
shall cease to be so before thy
resume grows too much longer.

The assumption that really cracks me up is:

> > > 7. You can freely cast between any two pointer types

Cast a char * to int * on any architecture with strong alignmenmt
restrictions and watch your code commit messy suicide.

Granted making the assumption and catching the faults might be
better than complicating mainline code. I'm somewhat amazed by
that notion, but not prepared to argue the point as a question
of kernel design, particularly not against Alan.

However, as an assumption purported to describe Albert's
"sane compiler and sane hardware" this is utter nonsense.
Quite a few architectures have hardware alignment restrictions,
and even on those that don't the compiler might reasonably
apply some for efficiency reasons.

-
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/

- Next message: James Tunnicliffe: "2.4.0-test2 default config problem"
- Previous message: Amit Dror: "vmalloc() in interrupt context"