Axter wrote:
> Ali wrote:
>> incompatible warning in C/C++
>>
>> I am using MS Visual C/C++ 6.0. I get the following warning when compiling
>>
>> C:model.ex.c(1221) : warning C4133: '=' : incompatible types - from
>> 'struct s_lsp_def *' to 'struct s_lsp_def *'
>>
>>
>> In the .h file, I have
>> ======================
>>
>> typedef struct s_lsp_def;
>>
>> typedef struct
>> {
>> int lsp_id;
>> int priority;
>>
>>
>> struct s_lsp_def* ptr_next_lsp_def;
>>
>>
>> }s_lsp_def;
>>
>> in a .c file, model.ex.c, I have
>> ================================
>>
>> int bcModel_add_lspToList ( s_lsp_def* the_ptr_lsp_def,
>> {
>>
>> s_lsp_def* curr_ptr_lsp_def;
>>
>> // the following line is the PROBLEM
>>
>> curr_ptr_lsp_def->ptr_next_lsp_def = the_ptr_lsp_def;
>>
>>
>> }
>>
>>
>> Does anyone understand why this warning.
>> Thanks.
> Try the following instead:
> typedef struct
> {
> int lsp_id;
> int priority;
> s_lsp_def* ptr_next_lsp_def;
> }s_lsp_def;
>
> You don't need the struct, since you're doing a typedef
>
Yes, but you can't use the typedef inside its own definition. But you
can use the incomplete struct type itself. You just need to name it
before using it, like so:
typedef struct s_lsp_def
{
int lsp_id;
int priority;
struct s_lsp_def* ptr_next_lsp_def;
} s_lsp_def;
This is valid in both C and C++. In C++ you don't need the typedef,
because a struct name works like a class name, so you can always use it
without putting 'struct' in front of it.
C++ only:
struct s_lsp_def
{
int lsp_id;
int priority;
s_lsp_def* ptr_next_lsp_def;
};
|