Topic: function declarations required?


Author: stephen.clamage@eng.sun.com (Steve Clamage)
Date: 1997/01/22
Raw View
In article PAA08417@erawan.cognex.com, Michael R Cook <mcook@cognex.com>
writes:
>Is this a valid ("well-formed") program?
>
>int main()
>{
>    return strlen("Hello, world.\n") != 0;
>}
>
>The point is that the program doesn't have a declaration for the function
>`strlen'.
>
>(I believe the code is invalid, but `gcc -Wall -ansi -pedantic' quietly
>accepts it.)

The program is invalid C++, because you cannot call a function unless
a prototype for it is in scope.

The program is valid C, because prototypes are optional, and the
standard library function strlen is called in a way that matches
its definition. Maybe you compiled the program as C instead of C++.
---
Steve Clamage, stephen.clamage@eng.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         ]
[ 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                             ]