Subject: Re: NetBSD/pdp10 ?
To: None <tech-kern@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 03/07/2002 06:45:38
>> Well, sloppy C programmers.  There are a few of us who know better.
> But we still do it!

"What you mean `we', white man?" :-)

> I THOUGHT C required that all data pointers be the same size,

No.  In particular, on machines whose addressing unit is larger than a
char, pointers to objects smaller than an addressing unit (usually only
char *, and perforce void *) are larger than pointers to objects that
are whole addressing units in size.

The ability to work with pointers to incomplete struct types does put
fairly strong restrictions on pointer-to-struct types, and similar
remarks apply to unions.  But I think that's about it.

> but that code pointers could be entirely different beasts?

Yes, that they may.

> Mind you some of the M$ code models might have broken this.

Well, M$ code models break a bunch of other C things (the most obvious
example is that they add new reserved words to the language).

> The fun starts if the 'null' pointer isn't the all-zero bit pattern.

Quite!

> Obviously you can't use bzero to clear a structure, I'm not sure what
> has to happen to pointers in the bss!

Uninitialized pointers must be nil, as if they were explicitly
initialized to 0.  (This may mean that on such an architecture you
can't put pointers in bss.  Or it may be better to have "integer bss"
and "pointer bss", or some such.)

> However the following are portable!
> 	fu *bar = 0;
> 	if (bar) ...

Right.  Also "bar = 0;" as an assignment, as well as an initialization.

> 	int x = 0;
> 	bar = (fu *)x;
> is not!

Well, it is portable in that it's legal C and it should compile
anywhere.  However, it's not guaranteed that bar will be a nil pointer
(or anything else useful) after the assignment.  (Indeed, I think it's
not guaranteed that the assignment will even complete.  Some machines
trap upon attempting to do anything, including a move to or from a
register, with certain invalid pointer values.)

> OTOH this breaks so much code,

Only code that's already broken (and perhaps whose brokenness just
hasn't yet been noticed).

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B