Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > incompatible warning in C/C++

Reply
Thread Tools

incompatible warning in C/C++

 
 
Ali
Guest
Posts: n/a
 
      12-20-2005
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.








 
Reply With Quote
 
 
 
 
Axter
Guest
Posts: n/a
 
      12-20-2005

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

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-20-2005
Ali wrote:
> incompatible warning in C/C++


There is no such thing as "C/C++". It's either C or it is C++. Find out
which and then post to the right newsgroup. If what you do is in fact C,
post to comp.lang.c. Post here again if it is (unlikely) C++.

> [...]


V
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      12-20-2005
Axter wrote:
> [..]
> 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


In C++ you don't need any typedef. You simply write

struct s_lsp_def
{
...
s_lsp_def *ptr;
};

V
 
Reply With Quote
 
Tydr Schnubbis
Guest
Posts: n/a
 
      12-20-2005
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;

};
 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      12-21-2005
"Victor Bazarov" <> wrote in message
news:%%Zpf.58640$ o.verio.net...
> Ali wrote:
>> incompatible warning in C/C++

>
> There is no such thing as "C/C++". It's either C or it is C++. Find out
> which and then post to the right newsgroup. If what you do is in fact C,
> post to comp.lang.c. Post here again if it is (unlikely) C++.
>
>> [...]

>
> V


Actually, since c++ allows C code, I think your statement is a bit
misleading Victor.

I've seen "There is no such thing as "C/C++" too many times on this
newsgroup and it is quite obvious what that the poster means "in C or
C++...".

Have you no concept of what / means?


 
Reply With Quote
 
deane_gavin@hotmail.com
Guest
Posts: n/a
 
      12-21-2005

Jim Langston wrote:
> "Victor Bazarov" <> wrote in message
> news:%%Zpf.58640$ o.verio.net...
> > Ali wrote:
> >> incompatible warning in C/C++

> >
> > There is no such thing as "C/C++". It's either C or it is C++. Find out
> > which and then post to the right newsgroup. If what you do is in fact C,
> > post to comp.lang.c. Post here again if it is (unlikely) C++.
> >
> >> [...]

> >
> > V

>
> Actually, since c++ allows C code, I think your statement is a bit
> misleading Victor.
>
> I've seen "There is no such thing as "C/C++" too many times on this
> newsgroup and it is quite obvious what that the poster means "in C or
> C++...".
>
> Have you no concept of what / means?


I have no concept of what "in C or in C++" means. They are different
languages and solutions to the same problem in one language are often
inappropriate or even incorrect in the other. So whether you say "in
C/C++" or in "in C or in C++" you are probably doing so because you
don't realise that, either way, it's a meaningless question.

The use of "C/C++" seems to me to imply some muddled thinking along the
lines of " I know they are kind of different but C++ is just a better C
so they are basically the same thing". In which case, correcting that
muddles thinking, as I think Victor did, is helpful.

Gavin Deane

 
Reply With Quote
 
Earl Purple
Guest
Posts: n/a
 
      12-21-2005

Victor Bazarov wrote:
> Ali wrote:
> > incompatible warning in C/C++

>
> There is no such thing as "C/C++". It's either C or it is C++. Find out
> which and then post to the right newsgroup. If what you do is in fact C,
> post to comp.lang.c. Post here again if it is (unlikely) C++.
>
> > [...]

>
> V


It is true there is no such language as C/C++ however you might want to
write header files that are compatible with both languages, as both
languages have the concept of a header file.

> typedef struct s_lsp_def;


Is that a valid forward declaration? typedef struct s_lsp_def to what?
Presumably you want to say that s_lsp_def is a typedef to an unknown
struct. I don't think that's allowed although it would be nice if it
were.

Now to answer the original problem, if you want to use the
struct/typedef features that is used in C then you should give the
struct a name, maybe s_lsp_def_tag. Then you can use that also within
the struct itself thus:

typedef struct s_lsp_def_tag
{
// code including a pointer to its own type
} s_lsp_def;

although I don't think you could use s_lsp_def for a forward
declaration.

 
Reply With Quote
 
Niklas Norrthon
Guest
Posts: n/a
 
      12-21-2005
"Jim Langston" <> writes:

> "Victor Bazarov" <> wrote in message
> news:%%Zpf.58640$ o.verio.net...
> > Ali wrote:
> >> incompatible warning in C/C++

> >
> > There is no such thing as "C/C++". It's either C or it is C++. Find out
> > which and then post to the right newsgroup. If what you do is in fact C,
> > post to comp.lang.c. Post here again if it is (unlikely) C++.
> >
> >> [...]

> >
> > V

>
> Actually, since c++ allows C code, I think your statement is a bit
> misleading Victor.


I think the statement above is more than a bit misleading.

A c++ compiler compiles C++ code. A c compiler compiles c code. C++
does *not* compile C code.

Try the following in your favorite c++ compiler:

struct class
{
enum { zero, one, two, three } new;
};

int main(void)
{
struct class throw;
return 0;
}

Or the following:

#include <stdlib.h>

int main(void)
{
int *x = malloc(1000 * sizeof *x);
/* do something useful with x */
free(x);
return 0;
}

/Niklas Norrthon

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      12-22-2005
Earl Purple wrote:
> Victor Bazarov wrote:
>> typedef struct s_lsp_def;


I didn't write that.

> Is that a valid forward declaration? typedef struct s_lsp_def to what?
> Presumably you want to say that s_lsp_def is a typedef to an unknown
> struct. I don't think that's allowed although it would be nice if it
> were.


You should simply write

struct s_lsp_def;

At least in C++ it's a valid forward-declaration of 's_lsp_def' as
a struct (class).

> [..]


V


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to remove warning: initialization from incompatible pointer type? wanglei0214@gmail.com C Programming 1 07-26-2006 04:56 PM
how to remove warning: initialization from incompatible pointer type? wanglei0214@gmail.com C Programming 2 07-26-2006 08:13 AM
how to remove warning: initialization from incompatible pointer type? wanglei0214@gmail.com C Programming 0 07-26-2006 07:51 AM
incompatible pointer type warning ? Michael C Programming 8 06-05-2006 09:17 PM
warning: incompatible implicit declaration of built-in function 'malloc'?? Paminu C Programming 7 02-07-2006 08:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57