undefined C struct forward declaration

Posted by robUK on Stack Overflow See other posts from Stack Overflow or by robUK
Published on 2009-03-07T05:19:12Z Indexed on 2010/05/23 23:31 UTC
Read the original article Hit count: 297

Filed under:
|
|
|

Hello,

I have a header file port.h, port.c, and my main.c

I get the following error: 'ports' uses undefined struct 'port_t'

I thought as I have declared the struct in my .h file and having the actual structure in the .c file was ok.

I need to have the forward declaration as I want to hide some data in my port.c file.

In my port.h I have the following:

/* port.h */
struct port_t;

port.c:

/* port.c */
#include "port.h"
struct port_t
{
    unsigned int port_id;
    char name;
};

main.c:

/* main.c */
#include <stdio.h>
#include "port.h"

int main(void)
{
struct port_t ports;

return 0;
}

Many thanks for any suggestions,

© Stack Overflow or respective owner

Related posts about c

    Related posts about struct