cvs commit: src/usr.bin/chat Makefile

Harti Brandt brandt at fokus.fraunhofer.de
Thu Oct 30 01:25:35 PST 2003


On Thu, 30 Oct 2003, Peter Jeremy wrote:

PJ>On Tue, Oct 28, 2003 at 10:28:24PM +1100, Bruce Evans wrote:
PJ>>Similarly for `return (log(3));`.  gcc doesn't do the log() inline, at
PJ>>least on i386's with no options, but it knows to pass 3.0 and convert
PJ>>the return value to int.
PJ>
PJ>It shouldn't.  If I write:
PJ>	int foo(int x)
PJ>	{
PJ>		return (log(x));
PJ>	}
PJ>without explicitly declaring any prototype for log(), gcc should
PJ>assume a declaration "int log(int);".  Arbitrarily deciding that
PJ>the declaration should be "double log(double);" breaks K&R C and
PJ>C90 programs.
PJ>
PJ>It seems that gcc is diverging more and more from the ISO standards.

I brought up this topic on gcc-patches. The answer was the
5th paragraph of 7.1.3:

"All identifiers with external linkage in any of the following subclauses
(including the future library directions) are always reserved for use as
identifiers with external linkage."

This seems to mean that your above code snippet is not legal, because
log() impicitly gets external linkage, but is reserved by the library.
Having a static log() should be ok, but will trigger that anoying gcc
shadow warning. Well, whether this makes sense or not is questionable.
Warnings should warn you not only when you invoke undefined behaviour, but
also when you do something dangerous. In

static void
log(int i)
{
....
}

someone else later might remove the 'static' which then leads to undefined
behaviour. So the gcc-people think they'd rather warn here.

You are invited to take part in the discussions on the list.

harti
-- 
harti brandt,
http://www.fokus.fraunhofer.de/research/cc/cats/employees/hartmut.brandt/private
brandt at fokus.fraunhofer.de, harti at freebsd.org


More information about the cvs-src mailing list