473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

incompatible warning in C/C++

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
9 2532

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
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
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
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
"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

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

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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian Stubblefield | last post by:
Dear clc members, I am rather new to the C programming language. I have a rather large program that I am currently debugging. Currently, the following snippet of code in the c program: ...
7
by: Brian Stubblefield | last post by:
Dear clc members, I am new to C and am posting several messages concerning a large C program that I am debugging. I am encountering a "incompatible types in assignment" warning for the...
15
by: Chris Readle | last post by:
Hi all, Somewhat new to C and I'm getting the following error from my latest code. Here's the warning I'm getting: chris_readle_project3_assignment3.c: In function `main':...
1
by: Josh Wilson | last post by:
Hey gang, So I have my stdin which is user defined file, and am wanting to write it to a temporary file (seems odd I know, but there is a sincere reason), and then use that file as the stdin for...
7
by: Paminu | last post by:
On a gentoo linux system i don't get any warnings when I comlpile this code: #include <stdio.h> typedef struct test { void *content; struct test_ *bob; } test_;
6
by: PraZ | last post by:
Hi all. Here is a simple code, which when compiled with gcc results in the warning "incompatible pointer type" for arg 1, as expected. But this is just what I want to do, because it makes it...
8
by: Michael | last post by:
Hi all, why do I get a message: warning: passing arg 1 of `collectInput' from incompatible pointer type In 'main' have: char inputString; collectInput(&inputString);
1
by: wanglei0214 | last post by:
I compiles a program in SLOS, but there is a warning i donot know how to remove? here is the framework of the code: typedef struct device_tree { ...... union {
0
by: srikar | last post by:
Hi all, I am having a problem, when I am compiling the code in 32 bit option on a 64 bit machine using the macro CPPFLAGS= -m32 I am getting the following warnings from the linker . ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.