开发者

difference between 2 different implementations of declaring structures

开发者 https://www.devze.com 2023-02-24 04:47 出处:网络
gcc 4.4.4 c89 I am wondering what is the real difference between the following 2 implementations of defining structures?
gcc 4.4.4
c89

I am wondering what is the real difference between the following 2 implementations of defining structures?

channel.h file

struct channel_tag;

struct channel_tag* init_channel(size_t channel_id);
void dispose_channels(struct channel_tag *channel);

channel.c file

typedef struct channel_tag {
    size_t channel_id;
} channel_t;

=================== Second implemenation ===============

channel.h file

typedef struct channel_tag channel;

channel* init_channel(size_t channel_id);
void dispose_channels(channel *channel);

channel.c file

struct channel_tag {
    size_t channel_id;
};

M开发者_Go百科any thanks for any suggestions,


In the first case you have one data type, and the second you have two (where the 2nd is typedef'ed to the first). There is no difference in the generated code. Its for many people just more convenient to read/write code that omits the extra struct keyword.


There is nothing different in the implementations. Its just a matter of choice. I prefer the second one in terms of readability. The extra "_tag" is ugly. Linux kernel coding style prefers all structure definitions without typedef.

0

精彩评论

暂无评论...
验证码 换一张
取 消