Warning Call to Function w/no Prototype in 
Author Message
 Warning Call to Function w/no Prototype in

I'm getting a warning with borland 4.0

Call to function print with no prototype in function main.

Simplified example:

main()
{
void funct();



Fri, 09 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in
I'm getting a warning on borland 4.0.

Warning Call to Function w/no Prototype in function main.

no matter where i put the prototype.

Example:

main ()
  {
   void funct();
   .
   .
   funct();
   .
  }

funct()
  {
  .
  .
  }

Thanks for any help.

Bill Haushalter
Austin TX



Fri, 09 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

Quote:
> I'm getting a warning on borland 4.0.
> Warning Call to Function w/no Prototype in function main.
> no matter where i put the prototype.

The prototype belongs outside of main.  For instance:

#include <stdio.h>

void foo( void );

int main()
{
        foo()
        return 0;

Quote:
}

void foo()
{
        printf("Hello there.\n");

Quote:
}

                                               -michael
--
Michael Jarvis   |  Finger for PGP Public key  |   QNSnet Technical Support

GCS d H- s+++: g? p+ au a25 w+ v C++++ USL++++$ P++++ L++>+++ 3- E--- N++ K
W-- M- !V po Y+ t+ 5 j R G+ tv b+++ D++ B- e+>++ u+ h---(*) f+ r+++ !n y+++


Fri, 09 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

Quote:

>I'm getting a warning with borland 4.0
>Call to function print with no prototype in function main.

I'll assume you mean 'printf'. If you raelly mean 'print' then this is perhaps
the problem.  Lookup the entry for 'printf' in your compiler help/manual and
it will tell you what file to #include before using the function.

Quote:
>Simplified example:
>main()
>{
>void funct();

Yes, very simplified.  Where's the 'print' ?

Claude.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 vv    vv       David Claude Brown

 ||     | /
 /\------/
(oo)
(~~)



Sat, 10 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

|> > I'm getting a warning on borland 4.0.
|>
|> > Warning Call to Function w/no Prototype in function main.
|>
|> > no matter where i put the prototype.
|>
|> The prototype belongs outside of main.  For instance:
|>
  I don't believe this to be the case -- the prototype can be given
  mixed in with the declarations in the body of 'main()'. What the
  compiler *may* be warning about is its opinion that "void foo();"
  is not an ANSI-prototype -- I believe that the original post had
  such an incomplete specification, which provides *no* information
  about the arguments to be passed in calling the function (and, so,
  richly deserves such a warning ...).

|> #include <stdio.h>
|>
|> void foo( void );
|>
|> int main()
|> {
|>   foo()
|>   return 0;
|> }
|>
|> void foo()
|> {
|>   printf("Hello there.\n");
|> }
|>
|>                                                -michael
|> --

--
 Ed Hook                              |       Coppula eam, se non posit
 Computer Sciences Corporation        |         acceptera jocularum.
 NASA Langley Research Center         | Me? Speak for my employer?...<*snort*>



Sat, 10 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

Quote:

> I'm getting a warning on borland 4.0.

> Warning Call to Function w/no Prototype in function main.

> no matter where i put the prototype.

----[example snipped]----

void funct();

int main(void)
{
  .
  .
  funct();
  .

Quote:
}

(type) funct(void)  /* (type) should be replaced by the type of the value
                       returned by the function */
{
 .
 .

Quote:
}

I think your problem was resolved by declaring the prototype at the start of
the program. Also functions should really have all their type specifiers
declared so they are matched up properly with their prototypes.

--
_____________________________________________________________________________
Until next time...           __  __  ___            
                            |__)|  |   /                        
                            |   |__|  /__    Creator of alt.music.abba


_____________________________________________________________________________
... Hmmmmmm... I'm hearing those happy gurgly noises again! :-)



Sat, 10 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

Quote:

>I'm getting a warning on borland 4.0.

>Warning Call to Function w/no Prototype in function main.
>no matter where i put the prototype.

>Example:
>main ()
>  {
>   void funct();

This is not a prototype.  The compiler wants to know what kind of parameters
the function takes.  funct() takes no parameters, so its prototype is:
    void funct(void);

Quote:
>   .
>   .
>   funct();
>   .
>  }

--
John Breckenridge                                Boothroyd Dewhurst, Inc.



Sat, 10 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in


Quote:
>I'm getting a warning on borland 4.0.

>Warning Call to Function w/no Prototype in function main.

Your forst message mentioned print. If you meant printf then this is a
simply case of calling a standard library function without including its
related header file (stdio.h in the case of printf).

Quote:
>no matter where i put the prototype.

>Example:

>main ()
>  {
>   void funct();

This is a declaration for funct. If your compiler is really complaining
about funct in this case then it is being very picky. The skeleton of your
code here is correct and the compiler is required to compile and run it
correctly (of course something you omitted may be at fault).

A prototype is something very specific - it is a function declaration which
includes type information for the parameters i.e. the new style ANSI
declarations. So

 main ()

 main (argc, argv)
 int argc;
 char *argv[];
 {}

 void func();

are not prototypes but:

 main (int argc, char *argv[])

 void func(void);

are prototypes.

--
-----------------------------------------


-----------------------------------------



Sat, 10 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

Quote:
>I'm getting a warning on borland 4.0.

>Warning Call to Function w/no Prototype in function main.

>no matter where i put the prototype.

>Example:

>main ()
>  {
>   void funct();
>   .
>   .
>   funct();
>   .
>  }

>funct()
>  {
>  .
>  .
>  }

The problem is that your prototype doesn't match the function definition
and the compiler is confused, no matter where you put the prototype.
Fix the prototype and everything should be OK.

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Sun, 11 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

Quote:

>> I'm getting a warning on borland 4.0.

>> Warning Call to Function w/no Prototype in function main.

>> no matter where i put the prototype.

>The prototype belongs outside of main.  For instance:

Huh?  What's wrong with a (correct) prototype inside main?

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Sun, 11 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

writes:

Quote:
>I'm getting a warning on borland 4.0.
>Warning Call to Function w/no Prototype in function main.
>no matter where i put the prototype.
>Example:
>main ()
>  {
>   void funct();

    ^^^^^^^^^^^^
the prototype for function taking no arguments and returning nothing is:
    void funct(void);

Quote:
>   funct();
>  }
>funct()
>  {
>  }

--

* Chicago, IL (USA)    


Sun, 11 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

Quote:

> I'm getting a warning on borland 4.0.

> Warning Call to Function w/no Prototype in function main.

> no matter where i put the prototype.

> Example:

> main ()
>   {
>    void funct();
>    .
>    .
>    funct();
>    .
>   }

> funct()
>   {
>   .
>   .
>   }

> Thanks for any help.

> Bill Haushalter
> Austin TX

In your sample code as posted, you provided a declaration of funct(),
but not a prototype.  A declaration tells the compiler the type of the
return value.  A prototype further specifies the types of the parameters,
if any.  If the function accepts no parameters, you can say so as follows:

    void funct( void );

Another point: your declaration specified the type as void, but your
function definition implicitly specified it as int.  I haven't used
Borland 4.0, but my Borland 3.0 would have complained about that as well.

Scott McKellar
Southwestern Bell Telephone
St. Louis, MO



Wed, 14 Jan 1998 03:00:00 GMT  
 Warning Call to Function w/no Prototype in

writes:
<snip>
|> > main ()
|> >   {
|> >    void funct();
|> >    .
|> >    .
|> >    funct();
|> >    .
|> >   }
|> >
|> > funct()
|> >   {
|> >   .
|> >   .
|> >   }
<snip>
|> Another point: your declaration specified the type as void, but your
|> function definition implicitly specified it as int.  I haven't used
|> Borland 4.0, but my Borland 3.0 would have complained about that as well.

Just to be clear, the ANSI standard does not require diagnostic in this case:
it is an example of undefined behaviour. A user-friendly compiler should give
an error anyway ...

(The reason is that at the point of definition of the function, the previous
declaration has gone out of scope. A compiler need not remember the
conflicting declaration. The behaviour is undefined, because
1) the linker is allowed to be smart and look for a funct that returns void,
which it won't find,
2) the call sequence for a void function may be different from that of an int
function, leading to problems at run time.)

As usual, the reasons are my invention: the standard does not state things in
exactly this way. (This is best seen by noting that if the call to funct()
was missing in main, the standard still specifies undefined behaviour if the
definition of main is present, and no error when no definition exists. This
combination cannot be deduced from my arguments (1) and (2): sometimes
simplicity of framing the rules makes them difficult to justify).

Cheers
Tanmoy
--

Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87544-0285,USA H:#3,802,9 St,NM87545
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]



Fri, 16 Jan 1998 03:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Help with gcc warnings/function prototype

2. free as a function argument and compiler warning on prototype

3. call to function prototypes

4. how to prototype a function call

5. Function prototype that RUNDLL32 calls?

6. Call to function with no prototype

7. Calling a function by ptr, getting a compiler warning

8. No warnings for prototype erros

9. Function returning a function-pointer - how to prototype ?

10. prototype (?) of function passed to function

11. Function prototypes for pointers to functions.

12. HELP: function prototype with pointer to function as parameter

 

 
Powered by phpBB® Forum Software