Help with gcc warnings/function prototype 
Author Message
 Help with gcc warnings/function prototype

Hello,

 I'm compiling this really simple file with gcc 3.0.3 and can't get rid
of this warning :

mybox[~]gcc -c test.c -Wall -Wimplicit -Wreturn-type -Wunused -Wswitch -Wcomment -Wuninitialized -Wparentheses -Wtraditional -Wpointer-arith -Wmissing-prototypes -O
test.c:5: warning: no previous prototype for `newErrorPtr'

 However I declared the function in the header file (see below)...

 Any hints ?

 Thanks.

        Eugne

file: test.h
#ifndef _TEST_H_
#define _TEST_H_

typedef struct {
  int error;
  char* desc;

Quote:
} _errorCtxt, *errorCtxtPtr;

errorCtxtPtr newErrorPtr();

#endif

File: test.c
#include <stdlib.h>

#include "test.h"

errorCtxtPtr newErrorPtr() {
  errorCtxtPtr tmp = (errorCtxtPtr) malloc(sizeof(_errorCtxt));
  if (tmp != NULL) {
    tmp->error = -1;
    tmp->desc = 0;
  }
  return tmp;

Quote:
}



Sat, 20 Nov 2004 00:39:11 GMT  
 Help with gcc warnings/function prototype

Quote:
> Hello,
>  I'm compiling this really simple file with gcc 3.0.3 and can't get rid
> of this warning :
> mybox[~]gcc -c test.c -Wall -Wimplicit -Wreturn-type -Wunused -Wswitch -Wcomment -Wuninitialized -Wparentheses -Wtraditional -Wpointer-arith -Wmissing-prototypes -O
> test.c:5: warning: no previous prototype for `newErrorPtr'
>  However I declared the function in the header file (see below)...
>  Any hints ?
>  Thanks.
>    Eugne
> file: test.h
> #ifndef _TEST_H_
> #define _TEST_H_
> typedef struct {
>   int error;
>   char* desc;
> } _errorCtxt, *errorCtxtPtr;
> errorCtxtPtr newErrorPtr();
> #endif
> File: test.c
> #include <stdlib.h>
> #include "test.h"
> errorCtxtPtr newErrorPtr() {
>   errorCtxtPtr tmp = (errorCtxtPtr) malloc(sizeof(_errorCtxt));
>   if (tmp != NULL) {
>     tmp->error = -1;
>     tmp->desc = 0;
>   }
>   return tmp;
> }

Try changing the definition of your function from errorCtxtPtr
newErrorPtr() to errorCtxtPtr newErrorPtr(void). An empty parameter list
causes the prototype to be incomplete.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"We're women. We've got double standards to live up to."
   - Ally McBeal



Sat, 20 Nov 2004 00:41:38 GMT  
 Help with gcc warnings/function prototype

Quote:

> Try changing the definition of your function from errorCtxtPtr
> newErrorPtr() to errorCtxtPtr newErrorPtr(void). An empty parameter list
> causes the prototype to be incomplete.

 It works ! thanks a lot !

        Eugne



Sat, 20 Nov 2004 00:47:49 GMT  
 Help with gcc warnings/function prototype

Quote:

> test.c:5: warning: no previous prototype for `newErrorPtr'

[...]

Quote:
> errorCtxtPtr newErrorPtr();

Here's your problem.  This is a declaration that does not provide
a prototype.  To turn it into a prototype, put `void' within the
parentheses.


Sat, 20 Nov 2004 00:56:42 GMT  
 Help with gcc warnings/function prototype

Quote:

> Hello,

>  I'm compiling this really simple file with gcc 3.0.3 and can't get rid
> of this warning :

> mybox[~]gcc -c test.c -Wall -Wimplicit -Wreturn-type -Wunused -Wswitch -Wcomment -Wuninitialized -Wparentheses -Wtraditional -Wpointer-arith -Wmissing-prototypes -O
> test.c:5: warning: no previous prototype for `newErrorPtr'

>  However I declared the function in the header file (see below)...

>  Any hints ?

>  Thanks.

>    Eugne

> file: test.h
> #ifndef _TEST_H_
> #define _TEST_H_

> typedef struct {
>   int error;
>   char* desc;
> } _errorCtxt, *errorCtxtPtr;

> errorCtxtPtr newErrorPtr();

> #endif

> File: test.c
> #include <stdlib.h>

> #include "test.h"

> errorCtxtPtr newErrorPtr() {
>   errorCtxtPtr tmp = (errorCtxtPtr) malloc(sizeof(_errorCtxt));
>   if (tmp != NULL) {
>     tmp->error = -1;
>     tmp->desc = 0;
>   }
>   return tmp;
> }

I get the sneaking feeling that you have shorted down the code to what you
believe is the minimum required to reproduce the problem but you have
actually trimmed it down too much.

The header file has the #ifndef statement. If you are compiling multiple
files, the first file to #include the header file will see its
contents. All subsequent #include statements will not because the #ifndef
will be false.

---

"iqgbgxmdbjlgdv.lksrqek.n";char *strchr(const char *,int); while
(*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}



Sat, 20 Nov 2004 04:56:41 GMT  
 Help with gcc warnings/function prototype

Quote:
> I'm compiling this really simple file with gcc 3.0.3 and can't get rid
>of this warning :

>mybox[~]gcc -c test.c -Wall -Wimplicit -Wreturn-type -Wunused -Wswitch -Wcomment -Wuninitialized -Wparentheses -Wtraditional -Wpointer-arith -Wmissing-prototypes -O
>test.c:5: warning: no previous prototype for `newErrorPtr'
>                               ^^^^^^^^^
> However I declared the function in the header file (see below)...

            ^^^^^^^^

Quote:
>errorCtxtPtr newErrorPtr();

Get into the habit of trying to understand what the compiler is
complaining about.  It doesn't complain about a missing *declaration*
for newErrorPtr, it complains about a missing *prototype* (that's why
you're using -Wmissing-prototypes, right?) and the fact that the function
is already declared is irrelevant, as long as the declaration is not a
prototype declaration.

Quote:
> Any hints ?

Don't use compiler options whose effect is not perfectly clear to you.

Dan
--
Dan Pop
DESY Zeuthen, RZ group



Sat, 20 Nov 2004 17:38:15 GMT  
 Help with gcc warnings/function prototype

Quote:

> #ifndef _TEST_H_
> #define _TEST_H_

I don't think you should have spelled _TEST_H_ that way.

 7.1.3  Reserved identifiers
[#1] Each header declares or defines all identifiers  listed
in  its  associated  subclause,  and  optionally declares or
defines identifiers listed in its associated future  library
directions   subclause  and  identifiers  which  are  always
reserved either for  any  use  or  for  use  as  file  scope
identifiers.

 -- All  identifiers  that  begin  with  an  underscore and
either an uppercase letter or  another  underscore  are
always reserved for any use.
-- All  identifiers  that  begin  with  an  underscore are
always reserved for use as identifiers with file  scope
in both the ordinary and tag name spaces.

--          
 pete



Sun, 21 Nov 2004 04:37:37 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. gcc function prototype type-checking

2. Warning Call to Function w/no Prototype in

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

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

5. help:prototype inconsistent with implementation of function

6. help:prototype inconsistent with implementation of function

7. function prototype help...

8. Function prototype question.need help.

9. Function Prototype help req.

10. help with function prototype

11. Help. pointer to function prototype

12. gcc -Wmissing-prototypes

 

 
Powered by phpBB® Forum Software