lint, pointers, 0 (what else?)

Thomas M. Breuel breuel at harvard.ARPA
Sat Feb 9 17:17:38 AEST 1985


> > [no good reason for sizeof(int)!=sizeof(char *)]
>
> Yes there is!  There is no good reason for you to be too lazy to allow it.
> C is a systems programming language.  I balk at having it bastardized into
> 
> STOP RUINING C FOR SYSTEMS PROGRAMMING.

Exactly. In a systems programming language I expect to have one
(pre-defined) integer type which can hold a pointer. 'C' *is* ruined in
that way that the kind of integer that can hold a pointer is not
pre-defined. This lack is not quite as noticable in 'C' as it is in
Pascal, for example, since you can do arithmetic with pointers easily 
in 'C', without converting them to integers first.

Of course you can 'typedef' such an integer type yourself. I would
prefer the integer type to be an 'int', and I still maintain that that
does not cause significant inefficiencies (being aware of forwarding to
'int' on procedure calles, ...). I would prefer it to be an 'int',
because that is what many programs expect, and because there are
certain notational conveniences extended to the 'int' type. Other
alternatives are to have the compiler pre-declare an integer type
(e.g.  'address') or to allow the programmer to re-declare 'int' to be
*any* integer data type.

> > The way K&R intended (and partially documented it).	
> 
> It isn't clear that they ever intended it to work this way.

Ok, I don't know whether K&R *intended* to work '0' as the nil pointer
on function call. Looking at 'stdio' and at V7 UN*X programs I just
can't help getting that impression, though.

> > While we are on the
> > subject, what about the same treatment for '-1', the (de facto) standard
> > error return value?
>
> Why not say that all integers are mappable to pointers, hey lets do away
> with types at all!

Yes, there should by an integer type such that 

    (AnyPointerType)(AddressIntegerType)(AnyPointerType)(exp)==(exp)

is always true. That's something I expect in a systems programming language. 

Looking at my assembly language programs, I find that I end up doing
95% of all operations with one data type: address (here meant to refer
to the integer type that can hold an address, i.e. 32bits on a 68000).
Maybe 4% are done with characters, and the remaining 1% with other
types. I would be perfectly happy with a systems programming language
that has only one data type: address.  Such languages exist and are
moderately successful. Unfortunatly, they are not widely available in
the UN*X world or on micros.

						Thomas.



More information about the Comp.lang.c mailing list