extern declaration inconsistency - (nf)

ks at ecn-ee.UUCP ks at ecn-ee.UUCP
Thu Apr 5 23:19:21 AEST 1984


#R:mit-eddi:-153800:ecn-ee:13100011:000:1241
ecn-ee!ks    Apr  4 15:58:00 1984

There is an important distinction between the following:

	extern char ch[];
	extern char *ch;

ch[] indicates that you have reserved space elswhere for some number of
characters and you can use ch as the address of the first reserved space.
*ch indicates that you reserved space for a pointer to some characters
which may or may not contain a valid value such that it points to some real
space that is holding some characters.  In the first case, ch is a "constant",
and in the second case, ch is a variable.

The confusion persists because when either form of ch is passed to a function
as a parameter, it is passed by value.  (The value of an array is the address
of it's first element.)  All function parameters can be modified as if they
were automatic variables, so both forms are equivalent only for function
parameter declarations.

In my opinion, this is a very elegant way of doing things, even if it
is confusing at first.

The REAL problem is that many C loaders do not flag the extern declaration
as an error.  They just load incorrect code.  So, the moral of the story is:

			>>>>	USE LINT    <<<<

The compiler is not meant to check for every little inconsistency.
That is why lint is around.

					Kirk Smith
					Purdue EE



More information about the Comp.lang.c mailing list