Walt Mankowski on Sun, 8 Dec 2002 18:12:05 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] C question: struct pointer error


On Sun, Dec 08, 2002 at 04:59:59PM -0500, Jeff Abrahamson wrote:
> I wonder if someone can help me see what I'm missing.
> 
> The following code snippet yields a warning and an error. I don't
> think it should. Am I confused, or is gcc?

You haven't done anything really *wrong*, it's just gcc being strict
because you told it to give all warnings.

>     int foo(struct bar *b);
> 
>     typedef struct bar {
> 	    int a;
>     } Bar;
> 
>     foo(Bar *b)
>     {
> 	    return 0;
>     }

A typedef isn't a #define.  Even though here they're different names
for the same structure, gcc warns that they're different.  To get rid
of the warning, either change the first line to

  int foo(Bar *b);

or the declaration of the subroutine foo to

  foo(struct bar *b)
  {
    return 0;
  }

Oh, and that form of declaration is deprecated since you're not
explicitly saying that it returns an int.  So you should really use

  int foo(Bar *b)
  {
    return 0;
  }

Walt

Attachment: pgprVzE8JzyBj.pgp
Description: PGP signature