C strongly typed?

lawrence.g.mayka lgm at cbnewsc.ATT.COM
Mon Mar 12 13:29:34 AEST 1990


In article <90070.034113CMH117 at psuvm.psu.edu> CMH117 at psuvm.psu.edu (Charles Hannum) writes:
>"void" in C is similar to "nil" in LISP.  It's just a generic type, which can
>hold the place of any other type, WHEN USED IN A POINTER!!  I couldn't assign

Some clarification is called for here.  In C, 'void' (*not* 'void *')
is used in function declarations and definitions to signify the
absence of arguments and/or a return value.  In this role, Common
Lisp's closest analog is the expression

	(VALUES)

which returns zero values.  (The VALUES form is more often used to
return multiple values.)  NIL is quite different.  In Common Lisp,
NIL is a specific object: the only object of type NULL, which is
in turn a subtype of both SYMBOL and LIST.  NIL's existence is
just as tangible as that of the number 0.  NIL does, of course,
fulfil some special roles (e.g., as the default initializer for a
name binding).

C's 'void *', on the other hand, plays the role of a generic
pointer type, as you say.  Its closest Common Lisp analog is the
type T, which is a supertype of every type.  If I were forced at
gunpoint to write type declarations for a Lisp function's
arguments, I would declare each of them to be of type T, which
essentially asserts existence but nothing more.

Despite the syntax, 'void *' has no semantic connection to 'void'
at all as far as I can see.  Indeed, they are almost opposites:
"anything" vs. "nothing." Apparently, C compiler writers simply
decided to apply some new semantics to whatever unused syntax was
lying around.


	Lawrence G. Mayka
	AT&T Bell Laboratories
	lgm at ihlpf.att.com

Standard disclaimer.



More information about the Comp.lang.c mailing list