OK, so why _does_ ld resolve text against data?

Geoff Clare gwc at root.co.uk
Thu Aug 23 23:19:38 AEST 1990


In <38343 at ucbvax.BERKELEY.EDU> edward at ucbarpa.Berkeley.EDU (Edward Wang) writes:

>Why stop there, why not redefine index() while you're at it?
>Defining index to be a variable is easy to debug.  It'll most likely
>core dump on the call.  Unintentionally redefining index to be a function
>of exactly the same type, arguments and all, is uncatchable and much harder
>to debug.

It's not hard to catch at all.  In fact it is impossible to miss:

$ cat tmp.c
char *index(string, chr)
char *string;
char chr;
{
	*string = chr;
	return string;
}

main()
{
	(void) index("a", 'a');
	return 0;
}
$ lint tmp.c
tmp.c:
index multiply declared	tmp.c(4)  ::  llib-lc(269)
$ ^D

[This doesn't belong in unix.wizards any more: I have directed followups
only to comp.lang.c]
-- 
Geoff Clare <gwc at root.co.uk>  (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, Hayne Street, London EC1A 9HH, England.   Tel: +44-71-315-6600



More information about the Comp.unix.wizards mailing list