public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/49182] New: Fordward declarations of struct not usable in function pointer types.
@ 2011-05-26 23:10 brad.lionberger at intel dot com
  2011-05-26 23:12 ` [Bug c/49182] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: brad.lionberger at intel dot com @ 2011-05-26 23:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49182

           Summary: Fordward declarations of struct not usable in function
                    pointer types.
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: brad.lionberger@intel.com


A forward declaration of a struct to be used in a function pointer type
definition confuses the compiler.  The following code does not compile using
gcc but will with two other compilers.

// Forward declaration
typedef struct _a a;  

// Pointer to function with struct as parameter
typedef int (*FxnPointer)(a* WontComplie);

// Actual declaration of struct with function pointer type declared above.
typedef struct _a
{
    int foo;
    int bar;
    FxnPointer PtrToFxn;
} a;

int main(void)
{
    a test_struct;

    return 0;
}

Errors returned are as follows:
FxnPtrEx.c:13:3: error: redefinition of typedef ‘a’
FxnPtrEx.c:2:19: note: previous declaration of ‘a’ was here


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/49182] Fordward declarations of struct not usable in function pointer types.
  2011-05-26 23:10 [Bug c/49182] New: Fordward declarations of struct not usable in function pointer types brad.lionberger at intel dot com
@ 2011-05-26 23:12 ` pinskia at gcc dot gnu.org
  2011-05-26 23:23 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-05-26 23:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49182

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-05-26 23:10:11 UTC ---
This is invalid C but valid C++.  GCC is correct as typedef for the same type
is invalid for C.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/49182] Fordward declarations of struct not usable in function pointer types.
  2011-05-26 23:10 [Bug c/49182] New: Fordward declarations of struct not usable in function pointer types brad.lionberger at intel dot com
  2011-05-26 23:12 ` [Bug c/49182] " pinskia at gcc dot gnu.org
@ 2011-05-26 23:23 ` pinskia at gcc dot gnu.org
  2011-05-26 23:36 ` brad.lionberger at intel dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-05-26 23:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49182

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-05-26 23:12:03 UTC ---
I forgot to mention GCC compiles it correctly with the C++ front-end.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/49182] Fordward declarations of struct not usable in function pointer types.
  2011-05-26 23:10 [Bug c/49182] New: Fordward declarations of struct not usable in function pointer types brad.lionberger at intel dot com
  2011-05-26 23:12 ` [Bug c/49182] " pinskia at gcc dot gnu.org
  2011-05-26 23:23 ` pinskia at gcc dot gnu.org
@ 2011-05-26 23:36 ` brad.lionberger at intel dot com
  2011-05-26 23:45 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: brad.lionberger at intel dot com @ 2011-05-26 23:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49182

--- Comment #3 from Brad <brad.lionberger at intel dot com> 2011-05-26 23:23:17 UTC ---
(In reply to comment #2)
> I forgot to mention GCC compiles it correctly with the C++ front-end.

Removing the typedefs will still cause compilation to error out not knowing
what a is.  For example:

// Forward declaration
struct a;  

// Pointer to function with struct as parameter
typedef int (*FxnPointer)(a* WontComplie);

// Actual declaration of struct with function pointer type declared above.
struct _a
{
    int foo;
    int bar;
    FxnPointer PtrToFxn;
} a;

int main(void)
{    
    return 0;
}

Resutls are :
FxnPtrEx.c:5:28: error: expected ‘)’ before ‘*’ token
FxnPtrEx.c:12:2: error: expected specifier-qualifier-list before ‘FxnPointer’

It seems to not take the forward declaration of the struct as a member of the
parameter list of the FxnPointer type, unless I am missing something here.

What I am trying to do is create a function pointer that takes in as a
parameter a pointer to a structure, but in that structure is a function pointer
of that type.  I am confused as to why the forward declaration is not working
here.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/49182] Fordward declarations of struct not usable in function pointer types.
  2011-05-26 23:10 [Bug c/49182] New: Fordward declarations of struct not usable in function pointer types brad.lionberger at intel dot com
                   ` (2 preceding siblings ...)
  2011-05-26 23:36 ` brad.lionberger at intel dot com
@ 2011-05-26 23:45 ` pinskia at gcc dot gnu.org
  2011-05-26 23:48 ` redi at gcc dot gnu.org
  2011-05-27  1:24 ` brad.lionberger at intel dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-05-26 23:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49182

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-05-26 23:36:43 UTC ---
This works:
// Forward declaration
typedef struct _a a;

// Pointer to function with struct as parameter
typedef int (*FxnPointer)(a* WontComplie);

// Actual declaration of struct with function pointer type declared above.
struct _a
{
    int foo;
    int bar;
    FxnPointer PtrToFxn;
};

int main(void)
{
    a test_struct;

    return 0;
}


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/49182] Fordward declarations of struct not usable in function pointer types.
  2011-05-26 23:10 [Bug c/49182] New: Fordward declarations of struct not usable in function pointer types brad.lionberger at intel dot com
                   ` (3 preceding siblings ...)
  2011-05-26 23:45 ` pinskia at gcc dot gnu.org
@ 2011-05-26 23:48 ` redi at gcc dot gnu.org
  2011-05-27  1:24 ` brad.lionberger at intel dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-26 23:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49182

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-05-26 23:44:43 UTC ---
(In reply to comment #3)
> (In reply to comment #2)
> > I forgot to mention GCC compiles it correctly with the C++ front-end.
> 
> Removing the typedefs will still cause compilation to error out not knowing
> what a is.  For example:
> 
> // Forward declaration
> struct a;  

You've declared the type "struct a"

> // Pointer to function with struct as parameter
> typedef int (*FxnPointer)(a* WontComplie);

You've tried to use "a" which is undeclared

> // Actual declaration of struct with function pointer type declared above.
> struct _a
> {
>     int foo;
>     int bar;
>     FxnPointer PtrToFxn;
> } a;

Now you've declared a variable called "a" with type "struct _a"


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/49182] Fordward declarations of struct not usable in function pointer types.
  2011-05-26 23:10 [Bug c/49182] New: Fordward declarations of struct not usable in function pointer types brad.lionberger at intel dot com
                   ` (4 preceding siblings ...)
  2011-05-26 23:48 ` redi at gcc dot gnu.org
@ 2011-05-27  1:24 ` brad.lionberger at intel dot com
  5 siblings, 0 replies; 7+ messages in thread
From: brad.lionberger at intel dot com @ 2011-05-27  1:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49182

--- Comment #6 from Brad <brad.lionberger at intel dot com> 2011-05-26 23:48:27 UTC ---
(In reply to comment #5)
> (In reply to comment #3)
> > (In reply to comment #2)
> > > I forgot to mention GCC compiles it correctly with the C++ front-end.
> > 
> > Removing the typedefs will still cause compilation to error out not knowing
> > what a is.  For example:
> > 
> > // Forward declaration
> > struct a;  
> You've declared the type "struct a"
> > // Pointer to function with struct as parameter
> > typedef int (*FxnPointer)(a* WontComplie);
> You've tried to use "a" which is undeclared
> > // Actual declaration of struct with function pointer type declared above.
> > struct _a
> > {
> >     int foo;
> >     int bar;
> >     FxnPointer PtrToFxn;
> > } a;
> Now you've declared a variable called "a" with type "struct _a"

Ah, I see now!  Thank you very much.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-05-26 23:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-26 23:10 [Bug c/49182] New: Fordward declarations of struct not usable in function pointer types brad.lionberger at intel dot com
2011-05-26 23:12 ` [Bug c/49182] " pinskia at gcc dot gnu.org
2011-05-26 23:23 ` pinskia at gcc dot gnu.org
2011-05-26 23:36 ` brad.lionberger at intel dot com
2011-05-26 23:45 ` pinskia at gcc dot gnu.org
2011-05-26 23:48 ` redi at gcc dot gnu.org
2011-05-27  1:24 ` brad.lionberger at intel dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).