By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

incompatible warning in C/C++

P: n/a
Ali
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.


Dec 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a

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

Dec 20 '05 #2

P: n/a
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
Dec 20 '05 #3

P: n/a
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
Dec 20 '05 #4

P: n/a
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;

};
Dec 20 '05 #5

P: n/a
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:%%*******************@newsread1.mlpsca01.us.t 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?
Dec 21 '05 #6

P: n/a

Jim Langston wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:%%*******************@newsread1.mlpsca01.us.t 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

Dec 21 '05 #7

P: n/a

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.

Dec 21 '05 #8

P: n/a
"Jim Langston" <ta*******@rocketmail.com> writes:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:%%*******************@newsread1.mlpsca01.us.t 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

Dec 21 '05 #9

P: n/a
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
Dec 22 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.