Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 01 Feb 2002 04:29:07 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Juha Juntunen <estabur@hotmail.com>
Cc:        chat@FreeBSD.ORG
Subject:   ANSI C prototypes in scope
Message-ID:  <3C5A8A13.3F6F490F@mindspring.com>
References:  <F81KDSpCW4uFWjkOTGk0000065d@hotmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This isn't a -arch question; moved to -chat, since it's
not even really FreeBSD related...

Juha Juntunen wrote:
> >>>static int  sendfile __P((struct printer *pp, int type, char *file,
> >>>                           int format));
> >>>
> >>>for a procedure declaration of:
> >>>      static int
> >>>      sendfile(pp, type, file, format)
> >>>              struct printer *pp;
> >>>              int type;
> >>>              char *file;
> >>>              char format;
> >>>      {
> >>
> >>That's *EXCATLY* why I'm converting the old, but still legal in c89,
> >>style to new style.  You get warnings that you didn't get before.
> >
> >The compiler is broken, if it accepts the second when the
> >first prototype is in scope.
> >
> >It's a broken compiler, period.
> 
> How is the compiler broken, question mark.
> 
> Are you perhaps objecting to the type of the last parameter
> ("int format" vs "char format")?  Please see Ansi Classic, chapter
> "3.5.4.3 Function declarators (including prototypes)", in particular
> page 69 lines 19-22.  In C99, 6.7.5.3 paragraph #11 seems to apply
> similarly.
> 
> If you
>         - define "__P" suitably
>         - add "struct printer;" to file scope
>         - add "}" to complete the function definition
> to me, the above code fragment seems to constitute a valid
> ANSI C89 translation unit.

The compiler complains when the prototype doesn't match the
declaration when it is an ANSI style declaration, but not
when it is a K&R style declaration (same prototype).

Either it should complain for both, or complain for neither.

The representational geometry for the function declaration
should be irrelevent to whether or not the values match
once they are interned.

What this is saying is that the compare to the prototype is
occuring after the value is interned, and that the value is
being interned in K&R form from a K&R declaration.

Try switching which one has int and which one char; try adding
another chara parameter after the first one.

Complainging about prototypes matching functions should work
in both directions, sinch "matching" is commutative.

It really implies that the compiler could generate incorrect
code.

I might have a prototype in scope in one place and not another
with "char", and the K&R sign extension to int that is resulting
in the non-match in this case could result in non-working code
on some compiler (perhaps GCC).

In any case, the non-match not being caught, even though the
declaration is in scope, is really, really ugly.

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C5A8A13.3F6F490F>