Topic: C/C++ Explicit/Implicit Prototypes


Author: MWRon@metrowerks.com (MW Ron)
Date: 1997/05/22
Raw View
In article <randomj-ya02408000R2105970812390001@news.ozemail.com.au>,
randomj@ozemail.com.au (Craig McFarlane) wrote:

>Metrowerks say that ANSI is not clear about this, and that they are not in
>error.  However, it's pretty clear to me that gcc implements prototype
>checking properly, and CW doesn't.

Metrowerks did not say ANSI is not clear about this, Metrowerks stated
that we fully comply with the standards.  Metrowerks has a IDE opition or
pragma that if selected requires explicit prototypes, if selected it gives
a warning for implicit prototypes.

>Is it possible to clarify the ANSI C/C++ standard, and make it obvious that
>implied prototypes are correct?

Metrowerks CodeWarrior C++ compilers does not say that implied prototypes
are incorrect and under normal warnings selections it compiles without any
errors.  The require Prototypes options are on the same window as remap NL
to CR, use unsigned char.  It is not on with warnings.

However I do feel that this can be documented better to state explicit
prototypes in our reference.

Ron

--
     METROWERKS                                   Ron Liechty
 http://www.metrowerks.com     MWRon@metrowerks.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Steve Clamage <stephen.clamage@Eng.Sun.COM>
Date: 1997/05/20
Raw View
Craig McFarlane wrote:
>
> I've been having a discussion with the Metrowerks people about their
> implementation of CodeWarrior.  Specifically, about their language option
> "Requires Prototypes".  When this option is selected, the code...
>
> void Dummy( void) {
> }
>
> void DummyCall( void) {
>     Dummy();
> }
>
> ...produces warnings under CodeWarrior.

That is just plain wrong, except that a compiler can warn about anything
it likes. ("Warning: function name is not a Sanskrit verb.") Neither
C nor C++ has a requirement that you supply a prototype other than the
function definition if the definition is visible.

The requirement (5.2.2 Function call) is that a declaration for the
called
function be visible from the scope of the call. Every definition is also
a declaration (3.1 Declarations and definitions). I don't see what could
be more clear or explicit than that.

--
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: randomj@ozemail.com.au (Craig McFarlane)
Date: 1997/05/20
Raw View
Hi Y'all,
I've been having a discussion with the Metrowerks people about their
implementation of CodeWarrior.  Specifically, about their language option
"Requires Prototypes".  When this option is selected, the code...

void Dummy( void) {
}

void DummyCall( void) {
    Dummy();
}

...produces warnings under CodeWarrior.  The same code under gcc (with
-wAll which requires prototypes) doesn't.  This is because gcc accepts the
Dummy() definition as an implied prototype as long as it appears before any
references.  CodeWarrior on the other hand insists that *every* function
has an explicit prototype to avoid warnings, no matter where the definition
appears in relation to its references.

Metrowerks say that ANSI is not clear about this, and that they are not in
error.  However, it's pretty clear to me that gcc implements prototype
checking properly, and CW doesn't.

Is it possible to clarify the ANSI C/C++ standard, and make it obvious that
implied prototypes are correct?

thanks,
Craig.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Jimbo T <jtarrant@inri.co.uk>
Date: 1997/05/21
Raw View
Craig McFarlane wrote:
> I've been having a discussion with the Metrowerks people about their
> implementation of CodeWarrior.  Specifically, about their language option
> "Requires Prototypes".  When this option is selected, the code...
>
> void Dummy( void) {
> }
>
> void DummyCall( void) {
>     Dummy();
> }
>
> ...produces warnings under CodeWarrior.  The same code under gcc (with
> -wAll which requires prototypes) doesn't.



Author: fred@genesis.demon.co.uk (Lawrence Kirby)
Date: 1997/05/21
Raw View
In article <randomj-ya02408000R2105970812390001@news.ozemail.com.au>
           randomj@ozemail.com.au "Craig McFarlane" writes:

>Hi Y'all,
>I've been having a discussion with the Metrowerks people about their
>implementation of CodeWarrior.  Specifically, about their language option
>"Requires Prototypes".  When this option is selected, the code...
>
>void Dummy( void) {
>}
>
>void DummyCall( void) {
>    Dummy();
>}

There shouldn't be a problem here since void Dummy(void) {} *is* a
prototype, so there is prototype in scope for Dummy() when it is called in
DummyCall().

>...produces warnings under CodeWarrior.

There are situtaions where a compiler is required to generate a diagnostic,
however it is allowed to generate any extra diagnostics it likes, the only
requirement is that it successfully compiles and executes strictly
conforming programs.

> The same code under gcc (with
>-wAll which requires prototypes) doesn't.  This is because gcc accepts the
>Dummy() definition as an implied prototype as long as it appears before any
>references.

The definition of dummy *is* a prototype because it contains a parameter
type list. For example the following are ANSI prototypes:

void foo(long x);    /* Prototyped declaration */

void foo(long x)     /* Prototyped definition */
{
}

and the following are not prototypes, they are the old K&R C form:

void foo();          /* Non-prototyped declaration */

void foo(x)          /* Non-prototyped definition */
long x;
{
}

The prototype form of an empty parameter list is specified as void in C.

> CodeWarrior on the other hand insists that *every* function
>has an explicit prototype to avoid warnings, no matter where the definition
>appears in relation to its references.

Sounds like somebody is confusing the terms "declarartion" and "prototype".
But even so a preceding function definition acts as a perfectly good
declaration.

>Metrowerks say that ANSI is not clear about this, and that they are not in
>error.  However, it's pretty clear to me that gcc implements prototype
>checking properly, and CW doesn't.

ANSI is crystal clear on what a prototype is and when it is required.
CW's get-out is that it can generate any diagnostics it likes as long as
it compiles the code. If it fails to compile and execute correctly the
strictly conforming program:

void Dummy( void)
{
}

int main(void)
{
    Dummy();

    return 0;
}

It may warn as much as it likes during compilation and the messages may not
be factually correct but that isn't a conformance issue, it is simply a
quality of implementation issue.

--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]