Topic: prototypes required?


Author: christian.bau@isltd.insignia.com (Christian Bau)
Date: 2000/04/26
Raw View
In article <38FF89DD.AF6F85C3@tribble.com>, David R Tribble
<david@tribble.com> wrote:

> Christopher Eltschka wrote:
> > That is, the following would generate a warning:
> >
> > void foo(int);
> >
> > void foo(long) {} // warning: definition overloads different prototype
> >
> ...
> > I think this would be a reasonable warning; also, it's
> > easy to shut up by simply providing an appropriate
> > declaration before the definition.
>
> Which would be real pain if all you want to do is:
>
>     void foo(int);    // from a header file, e.g.
>
>     void foo(long x)  // useless warning here
>     {
>         foo((int) x);
>     }

If foo is indeed an extern function, then the warning is definitely not
useless! If foo (long x) is an external function, but not mentioned in the
header file, then it is quite likely that someone reads the source file,
finds two non-static functions named foo, and writes "foo (3L);" assuming
it calls foo (long x). When that programmer finds out WHY foo (long x) was
not called, he will add foo (long x) to the header file, which then
changes the meaning of all other calls to foo. There are two sensible ways
to add function foo (long):

1. Add it to the header file.
2. Make it static.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: David R Tribble <david@tribble.com>
Date: 2000/04/21
Raw View
Christopher Eltschka wrote:
>> Christian Bau wrote:
>> > In C++, another warning would make very much sense: If the
>> > compiler has found a declaration for a function named f, and
>> > later finds a function of a different function, named f, but with
>> > a different signature.
>
> As I understand him, he only wants a warning if a function
> which was not previously declared overloads another function
> which was declared but not defined.
>
> That is, the following would generate a warning:
>
> void foo(int);
>
> void foo(long) {} // warning: definition overloads different prototype
>
...
> I think this would be a reasonable warning; also, it's
> easy to shut up by simply providing an appropriate
> declaration before the definition.

Which would be real pain if all you want to do is:

    void foo(int);    // from a header file, e.g.

    void foo(long x)  // useless warning here
    {
        foo((int) x);
    }

--
David R. Tribble, mailto:david@tribble.com, http://david.tribble.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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Darin Adler <darin@bentspoon.com>
Date: 2000/04/12
Raw View
In article <8cth5m$se6$1@nnrp1.deja.com>, Jim Hyslop
<jim.hyslop@leitch.com> wrote:

> I thought the gcc port that Tornado uses for vxWorks also issued the
> warning, but a quick test shows that it doesn't.

It seems that gcc's -Wmissing-declarations option is intended for this
purpose:

`-Wmissing-declarations'
     Warn if a global function is defined without a previous
     declaration.  Do so even if the definition itself provides a
     prototype.  Use this option to detect global functions that are
     not declared in header files.

My quick test of it showed that it worked in C mode but not C++ mode,
despite the fact that it makes sense for C++ code too, despite the word
"prototype" in the description.

    -- Darin

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: christian.bau@isltd.insignia.com (Christian Bau)
Date: 2000/04/13
Raw View
In article <darin-4C2D88.09074711042000@fullnews.metawire.com>, Darin
Adler <darin@bentspoon.com> wrote:

> In article <8cth5m$se6$1@nnrp1.deja.com>, Jim Hyslop
> <jim.hyslop@leitch.com> wrote:
>
> > I thought the gcc port that Tornado uses for vxWorks also issued the
> > warning, but a quick test shows that it doesn't.
>
> It seems that gcc's -Wmissing-declarations option is intended for this
> purpose:
>
> `-Wmissing-declarations'
>      Warn if a global function is defined without a previous
>      declaration.  Do so even if the definition itself provides a
>      prototype.  Use this option to detect global functions that are
>      not declared in header files.
>
> My quick test of it showed that it worked in C mode but not C++ mode,
> despite the fact that it makes sense for C++ code too, despite the word
> "prototype" in the description.

In C++, another warning would make very much sense: If the compiler has
found a declaration for a function named f, and later finds a function of
a different function, named f, but with a different signature.

Very much likely to be an error, and it could lead to surprising results:
If the signatures are similar, like int f (int x) and int f (long x), a
call BEFORE the function definition could call a different function than a
call AFTER the function definition.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Steve Clamage <stephen.clamage@sun.com>
Date: 2000/04/13
Raw View
Christian Bau wrote:
>
> In C++, another warning would make very much sense: If the compiler has
> found a declaration for a function named f, and later finds a function of
> a different function, named f, but with a different signature.

So you are saying you want a warning about every overloaded function?

Be prepared to get a lot such warnings, because the standard library
has dozens, if not hundreds, of overloaded functions.

--
Steve Clamage, stephen.clamage@sun.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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 2000/04/13
Raw View
Steve Clamage wrote:
>
> Christian Bau wrote:
> >
> > In C++, another warning would make very much sense: If the compiler has
> > found a declaration for a function named f, and later finds a function of
> > a different function, named f, but with a different signature.
>
> So you are saying you want a warning about every overloaded function?
>
> Be prepared to get a lot such warnings, because the standard library
> has dozens, if not hundreds, of overloaded functions.

As I understand him, he only wants a warning if a function
which was not previously declared overloads another function
which was declared but not defined.

That is, the following would generate a warning:

void foo(int);

void foo(long) {} // warning: definition overloads different prototype

but the following wouldn't:

void foo1(int) {}

void foo1(long) {} // no warning: foo1(int) is already defined

void foo2(int);
void foo2(long);   // no warning: no definition

void foo2(long) {} // no warning: foo2(long) was declared before

void foo3(long) {} // no warning: no overload


I think this would be a reasonable warning; also, it's
easy to shut up by simply providing an appropriate
declaration before the definition.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: christian.bau@isltd.insignia.com (Christian Bau)
Date: 2000/04/14
Raw View
In article <38F4DD58.BF3D38EE@sun.com>, Steve Clamage
<stephen.clamage@sun.com> wrote:

> Christian Bau wrote:
> >
> > In C++, another warning would make very much sense: If the compiler has
> > found a declaration for a function named f, and later finds a function of
> > a different function, named f, but with a different signature.
>
> So you are saying you want a warning about every overloaded function?
>
> Be prepared to get a lot such warnings, because the standard library
> has dozens, if not hundreds, of overloaded functions.

No, not every overloaded function, obviously. Consider:

In the header file:

   int f (int x);

In the source file:

   int f (int x) { return x + 1; } // No warning
   long f (long x) { return x + 2; } // WARNING!!!
   short f (short x) { return x + 3; } // WARNING!!!

Later in the source file a function contains

   short x = 3;
   short y = f (x); // Sets y to 6

I move this function to a different file that includes the header file.
Suddenly y is set to 4! Similar things happen if you move a function
around in a source file. An overloaded function call will give different
results depending on how many of the different declarations the compiler
has seen.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Roger Orr <roger_orr@my-deja.com>
Date: 2000/04/14
Raw View
In article <38F4DD58.BF3D38EE@sun.com>,
  Steve Clamage <stephen.clamage@sun.com> wrote:
> Christian Bau wrote:
> >
> > In C++, another warning would make very much sense: If the compiler
has
> > found a declaration for a function named f, and later finds a
function of
> > a different function, named f, but with a different signature.
>
> So you are saying you want a warning about every overloaded function?
>
> Be prepared to get a lot such warnings, because the standard library
> has dozens, if not hundreds, of overloaded functions.
>

I suspect this sort of warning would be of most use when trying to track
down 'obscure behaviour' in code which doesn't do what the programmer
'expects'.

An alternative approach in such cases might be a compiler option to
output some sort of 'canonical form' for each function called.

I for one would occasionally find a compiler which could _tell me_ which
overload was called very useful!

I'm not sure what syntax would be most useful, but even this:

input line:

  f(12, g() );

output line:

  f( /*long*/ 12, /* Base:: */ g( /* short = 3 */ ) );

would be a tool I'd love to have from time to time.

I don't suppose there's a compiler which can do this?!

Roger.


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Pete Becker <petebecker@acm.org>
Date: 2000/04/14
Raw View
Roger Orr wrote:
>
> I for one would occasionally find a compiler which could _tell me_ which
> overload was called very useful!
>

You can do it with a trick: compile to assembler and decipher the
mangled name.

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Contibuting Editor, C/C++ Users Journal (http://www.cuj.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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Yuriy Koblents-Mishke <koblents@lenny.haskins.yale.edu>
Date: 2000/04/14
Raw View

Pete Becker wrote:
>
> Roger Orr wrote:
> >
> > I for one would occasionally find a compiler which could _tell me_ which
> > overload was called very useful!
> >
>
> You can do it with a trick: compile to assembler and decipher the
> mangled name.
>

Are you doing this? How often, if yes?

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Pete Becker <petebecker@acm.org>
Date: 2000/04/14
Raw View
Yuriy Koblents-Mishke wrote:
>
> Pete Becker wrote:
> >
> > Roger Orr wrote:
> > >
> > > I for one would occasionally find a compiler which could _tell me_ which
> > > overload was called very useful!
> > >
> >
> > You can do it with a trick: compile to assembler and decipher the
> > mangled name.
> >
>
> Are you doing this? How often, if yes?
>

Once in a while, when I think that I don't really know what's going on.
It's usually easier to write a simpler source file:

#include "header.h"

f(g());

That way it's easy to find the call to f.

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Contibuting Editor, C/C++ Users Journal (http://www.cuj.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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 2000/04/15
Raw View
Roger Orr wrote:
>
> In article <38F4DD58.BF3D38EE@sun.com>,
>   Steve Clamage <stephen.clamage@sun.com> wrote:
> > Christian Bau wrote:
> > >
> > > In C++, another warning would make very much sense: If the compiler
> has
> > > found a declaration for a function named f, and later finds a
> function of
> > > a different function, named f, but with a different signature.
> >
> > So you are saying you want a warning about every overloaded function?
> >
> > Be prepared to get a lot such warnings, because the standard library
> > has dozens, if not hundreds, of overloaded functions.
> >
>
> I suspect this sort of warning would be of most use when trying to track
> down 'obscure behaviour' in code which doesn't do what the programmer
> 'expects'.
>
> An alternative approach in such cases might be a compiler option to
> output some sort of 'canonical form' for each function called.
>
> I for one would occasionally find a compiler which could _tell me_ which
> overload was called very useful!
>
> I'm not sure what syntax would be most useful, but even this:
>
> input line:
>
>   f(12, g() );
>
> output line:
>
>   f( /*long*/ 12, /* Base:: */ g( /* short = 3 */ ) );
>
> would be a tool I'd love to have from time to time.
>
> I don't suppose there's a compiler which can do this?!

I don't know one; however, given that template metaprogramming
consists of complete programs evaluated at compile time, a
"compile time debugger" would certainly be an advantage
- especially since we can't even do debugging print statements
at that phase.

A simple way to do that would be a flag that outputs all
the exact functions called when the call is generated,
together with the line where that call is generated
(to catch template specialisations).

For example, in the following case

template<class T> void foo(T&) {}
template<> void foo(int&) {}
template<class T> void foo(T*&) {}
void foo(double);
void foo(int*);

int main()
{
  int i;
  double d;
  char c, *p=c;
  foo(i);
  foo(&i);
  foo(d);
  foo(&d);
  foo(c);
  foo(p);
}

the ouput with the corresponding flag would be s.th. like:

foo.cc: in function int main()
foo.cc:12: calling void foo<int>(int&) (line 2)
foo.cc:13: calling void foo(int*) (line 5)
foo.cc:14: calling void foo(double) (line 4)
foo.cc:15: calling void foo<double* const>(double* const&) (line 1)
foo.cc:16: calling void foo<char>(char&) (line 1)
foo.cc:17: calling void foo<char>(char*&) (line 3)

For line 12, the (line 2) shows that the specialisation in line 2
is used, rather than the general template in line 1.
For line 15, it shows that not the pointer version (line 3),
but the normal version (line 1) is called (adding a const
pointer version explicitly would correct this).

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Yura Koblents-Mishke <yura@concentric.net>
Date: 2000/04/15
Raw View
Thank you!

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Ron Natalie <ron@sensor.com>
Date: 2000/04/06
Raw View

Paul Meyerholtz wrote:

>
> The question is; are prototypes required in C++ (standardized version)?

Functions must be fully declared prior to use.

>
> That is, is the following legal?
>
> void Hello () {
> ...
> }
>
> int main () {
>         Hello();
> }
>
> I know that if the Hello function followed main, a prototype would be
> required, but can you write it as above and still be in accordance with
> the standard?
>

In this case, the definition of the function is it's own declaration.  You
don't need an additional "prototype" here.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/04/06
Raw View
In article <38EADE70.C060A16F@ix.netcom.com>, Paul Meyerholtz
<pholtz@ix.netcom.com> writes
>
>I know that there is a standard available somewhere on the net, but I
>haven't quite reached the state that I want to wade through that
>document.  But if you answer by showing me where the standard is, I'll
>try to find the answer.
>
>The question is; are prototypes required in C++ (standardized version)?

Only if a full definition is not visible. I.e. a full definition acts as
a declaration and AFAIK the only kind of function declaration allowed in
C++ is a prototype (not true in C)

>
>That is, is the following legal?
Yes.

>
>
>void Hello () {
>...
>}
>
>int main () {
>       Hello();
>}
>
>
>I know that if the Hello function followed main, a prototype would be
>required, but can you write it as above and still be in accordance with
>the standard?
>
>Paul
>
>
>---
>[ 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    ]
>[              --- Please see the FAQ before posting. ---               ]
>[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]
>

Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: comeau@panix.com (Greg Comeau)
Date: 2000/04/07
Raw View
In article <8cfr0s$77t$1@nnrp1.deja.com> Jim Hyslop <jim.hyslop@leitch.com> writes:
>In article <38EADE70.C060A16F@ix.netcom.com>,
>  pholtz@ix.netcom.com wrote:
>> void Hello () {
>> ...
>> }
>> int main () {
>>  Hello();
>> }
>
>Certain compilers will issue a warning that you have not prototyped
>Hello(), but that's (IMO) a bogus warning.
>There is nothing to stop a compiler from issuing any warnings it wants to.

Maybe in the general case, but _exactly which compiler_ do you know
that will issue the warning that you have not prototyped Hello
_in the code above_?

- Greg
--
Comeau Computing, Producers of Comeau C/C++ 4.2.42 (4.2.43 BETA starting)
Try Comeau C++ online at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: christian.bau@isltd.insignia.com (Christian Bau)
Date: 2000/04/07
Raw View
In article <8cfr0s$77t$1@nnrp1.deja.com>, Jim Hyslop
<jim.hyslop@leitch.com> wrote:

> In article <38EADE70.C060A16F@ix.netcom.com>,
>   pholtz@ix.netcom.com wrote:
> > That is, is the following legal?
> >
> > void Hello () {
> > ...
> > }
>
> > int main () {
> >       Hello();
> > }
>
>
> Certain compilers will issue a warning that you have not prototyped
> Hello(), but that's (IMO) a bogus warning.  There is nothing to stop a
> compiler from issuing any warnings it wants to.  "Warning 1234:  Code
> was last modified on a Monday morning.  Are you sure you weren't
> suffering from a hangover?"

One compiler I use will indeed give a warning, but only if Hello () is
extern, and not if it is static. IMHO a good idea. If Hello () is extern,
then there should be a prototype in a header file, and the code should be
including that header file. If Hello () has no prototype in a header file,
then it should probably not be called from another file, so it should be
static.

Of course it is perfectly legal C++.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/04/08
Raw View
In article <8ch6m8$q1o$1@panix.com>, Greg Comeau <comeau@panix.com>
writes
>Maybe in the general case, but _exactly which compiler_ do you know
>that will issue the warning that you have not prototyped Hello
>_in the code above_?

CodeWarrior?


Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Jens Kilian <Jens_Kilian@agilent.com>
Date: 2000/04/08
Raw View
comeau@panix.com (Greg Comeau) writes:
> In article <8cfr0s$77t$1@nnrp1.deja.com> Jim Hyslop <jim.hyslop@leitch.com> writes:
> >In article <38EADE70.C060A16F@ix.netcom.com>,
> >  pholtz@ix.netcom.com wrote:
> >> void Hello () {
> >> ...
> >> }
> >> int main () {
> >>  Hello();
> >> }
> >
> >Certain compilers will issue a warning that you have not prototyped
> >Hello(), but that's (IMO) a bogus warning.
> >There is nothing to stop a compiler from issuing any warnings it wants to.
>
> Maybe in the general case, but _exactly which compiler_ do you know
> that will issue the warning that you have not prototyped Hello
> _in the code above_?

Metrowerks, with a certain option, and only for non-static functions IIRC.
It actually makes sense if you want to ensure that all your public functions
have prototypes.

 Jens.
--
mailto:jjk@acm.org                 phone:+49-7031-464-7698 (HP TELNET 778-7698)
  http://www.bawue.de/~jjk/          fax:+49-7031-464-7351
PGP:       06 04 1C 35 7B DC 1F 26 As the air to a bird, or the sea to a fish,
0x555DA8B5 BB A2 F0 66 77 75 E1 08 so is contempt to the contemptible. [Blake]

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Paul Meyerholtz <pholtz@ix.netcom.com>
Date: 2000/04/08
Raw View
Paul Meyerholtz wrote:
>
> I know that there is a standard available somewhere on the net, but I
> haven't quite reached the state that I want to wade through that
> document.  But if you answer by showing me where the standard is, I'll
> try to find the answer.
>
> The question is; are prototypes required in C++ (standardized version)?
>
> That is, is the following legal?
>
> void Hello () {
> ...
> }
>
> int main () {
>         Hello();
> }
>
Thanks for all the responses, now for a twist, are prototypes required
for default parameters?

Paul

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: comeau@panix.com (Greg Comeau)
Date: 2000/04/08
Raw View
In article <38EE4628.4FEE90F4@ix.netcom.com> pholtz@ix.netcom.com writes:
>are prototypes required for default parameters?

If I understand your question: Yes, and the defaults need to
be declared _before_ the call to be honored:

void foo(int);
void bar()
{
    foo(-99); // ok
    foo(); // error
}
void foo(int = 99);
var baz()
{
    foo(-99); // ok
    foo(); // "as if" foo(99);
}

- Greg
--
Comeau Computing, Producers of Comeau C/C++ 4.2.42 (4.2.43 BETA starting)
Try Comeau C++ online at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 2000/04/09
Raw View
Paul Meyerholtz wrote:
....
> Thanks for all the responses, now for a twist, are prototypes required
> for default parameters?

Some corrections to your terminology:
1. C has prototypes. C++ doesn't. A C prototype will usually qualify as
a C++ declaration. A K&R C function declaration usually won't.
2. Neither C nor C++ have anything called "default parameters".
3. C++ function parameters can have default arguments.

Given the terminology confusion, I'm not sure exactly what you're
asking. However, functions always need to be declared somewhere along
the line, whether or not they are used as default arguments. parameters
always need to be declared, whether or not they have default arguments.
Does that cover your question?

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/04/09
Raw View
In article <38EE4628.4FEE90F4@ix.netcom.com>, Paul Meyerholtz
<pholtz@ix.netcom.com> writes
>Thanks for all the responses, now for a twist, are prototypes required
>for default parameters?
NO
Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Jim Hyslop <jim.hyslop@leitch.com>
Date: 2000/04/11
Raw View
In article <8ch6m8$q1o$1@panix.com>,
  comeau@comeaucomputing.com wrote:
> In article <8cfr0s$77t$1@nnrp1.deja.com> Jim Hyslop
<jim.hyslop@leitch.com> writes:
> >In article <38EADE70.C060A16F@ix.netcom.com>,
> >  pholtz@ix.netcom.com wrote:
> >> void Hello () {
> >> ...
> >> }
> >> int main () {
> >>  Hello();
> >> }
> >
> >Certain compilers will issue a warning that you have not prototyped
> >Hello(), but that's (IMO) a bogus warning.
> >There is nothing to stop a compiler from issuing any warnings it
wants to.
>
> Maybe in the general case, but _exactly which compiler_ do you know
> that will issue the warning that you have not prototyped Hello
> _in the code above_?
The Motorola cross-code compiler.  Mind you, the version we have is a
very old one.  But it will issue the warning.

I thought the gcc port that Tornado uses for vxWorks also issued the
warning, but a quick test shows that it doesn't.

--
Jim
I ignore all email from recruitment agencies.  Except that
I reserve the right to send rude, nasty replies to recruiters.
Please do not send me email with questions - post
here.


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Paul Meyerholtz <pholtz@ix.netcom.com>
Date: 2000/04/06
Raw View
I know that there is a standard available somewhere on the net, but I
haven't quite reached the state that I want to wade through that
document.  But if you answer by showing me where the standard is, I'll
try to find the answer.

The question is; are prototypes required in C++ (standardized version)?

That is, is the following legal?


void Hello () {
...
}

int main () {
 Hello();
}


I know that if the Hello function followed main, a prototype would be
required, but can you write it as above and still be in accordance with
the standard?

Paul


---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Steve Clamage <stephen.clamage@sun.com>
Date: 2000/04/06
Raw View
Paul Meyerholtz wrote:
>
> I know that there is a standard available somewhere on the net, but I
> haven't quite reached the state that I want to wade through that
> document.  But if you answer by showing me where the standard is, I'll
> try to find the answer.

Refer to the FAQ list for this newsgroup (pointed to by the trailer
at the bottom of every posting).  It explains how do get a paper copy
or downloadable electronic version of the standard.

>
> The question is; are prototypes required in C++ (standardized version)?

Yes, they have always been required in C++, since the first published
book in 1986, if not earlier.

>
> That is, is the following legal?
>
> void Hello () {
> ...
> }
>
> int main () {
>         Hello();
> }

Yes, because you supplied a prototype. A function definition is its
own prototype.

That is, you can call a function only if it has been declared.  Any
definition is a declaration, and C++ requires every function
declaration to include the types of its parameters.

The term "function prototype" was introduced by the 1989 C standard,
which allows a function to be declared without specifying its
parameters. THus, C89 needs a distinction between "function declaration"
and "function prototype". C++ does not need the distinction, because
every function declaration and definition is also a prototype.

--
Steve Clamage, stephen.clamage@sun.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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Jim Hyslop <jim.hyslop@leitch.com>
Date: 2000/04/06
Raw View
In article <38EADE70.C060A16F@ix.netcom.com>,
  pholtz@ix.netcom.com wrote:
>
> I know that there is a standard available somewhere on the net, but I
> haven't quite reached the state that I want to wade through that
> document.  But if you answer by showing me where the standard is, I'll
> try to find the answer.
http://webstore.ansi.org $18 US, they take credit cards ;-)

> The question is; are prototypes required in C++ (standardized
> version)?
Yes, declarations are required.

> That is, is the following legal?
>
> void Hello () {
> ...
> }
This is both a definition and a declaration, therefore your main() below
is well-formed.  See 7 and 3.1 in the Standard (when you get it ;-)

> int main () {
>  Hello();
> }


Certain compilers will issue a warning that you have not prototyped
Hello(), but that's (IMO) a bogus warning.  There is nothing to stop a
compiler from issuing any warnings it wants to.  "Warning 1234:  Code
was last modified on a Monday morning.  Are you sure you weren't
suffering from a hangover?"

--
Jim
I ignore all email from recruitment agencies.  Except that
I reserve the right to send rude, nasty replies to recruiters.
Please do not send me email with questions - post
here.


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]