Structs with pointers

H

Hanno Boettcher

Hi there,

I got a little problem with a program I'm writing:

I use some structs, the definitions are as follows:

struct GitterPunkt{
float a[ANZ_SENSOREN];
float d[ANZ_SENSOREN];
float p[ANZ_SENSOREN];
float p4ges;
float p3ges;
float r;
float phi;
};

struct ErgMax{
struct Gitterpunkt *randlinks;
struct Gitterpunkt *randrechts;
struct Gitterpunkt *randunten;
struct Gitterpunkt *randoben;
struct Gitterpunkt *max3;
struct Gitterpunkt *max4;
};

struct GitterPunkt gitter[N][M]; /* N and M are definde like #define M
10 */

struct idl{
char id[ANZ_SENSOREN];
struct ErgMax *erg;
struct idl *next;
};


My Program is a bit long to post it here, but I think there are only few
lines important:

struct idl *aktid=0;
/* some code, aktid changes to !0 */
aktid->erg->randoben=&gitter[j]; /* it's in a loop with i and j for
counters */

I have got several assignments like the one above and I get the same
compilation error everytime:

auswerten.c:73: Warnung: Zuweisung von inkompatiblem Zeigertyp

Because I use a german system the warning is in german, too. In english
it's something like: "auswerten.c:73: Warning: Assigment with
incompatible Pointertype" (free translated)

I'm puzzled, I don't have any clue what is going wrong. Does anybody
here got an idea?

Normaly randoben should get a pointer to a Gitterpunkt (fix in i and j),
but the compiler says, that the pointer are incompatible...

Thx in advance
 
I

Irrwahn Grausewitz

Hanno Boettcher said:
Hi there,

I got a little problem with a program I'm writing:

I use some structs, the definitions are as follows:

struct GitterPunkt{ [...]
};

struct ErgMax{
struct Gitterpunkt *randlinks;
struct Gitterpunkt *randrechts;
struct Gitterpunkt *randunten;
struct Gitterpunkt *randoben;
struct Gitterpunkt *max3;
struct Gitterpunkt *max4;
^--- How a simple typo can mess things up.

struct Gitterpunkt != struct GitterPunkt

Regards
 
M

Malcolm

Hanno Boettcher said:
AHHH, thx!
<-- I'm with stupid
This is an argument for typedefing your structs.

typedef struct
{
int x;
/* blah */
}GitterPunkt.

Now if you type

Gitterpunkt *ptr;

the compiler should tell you that the declaration is invalid because it
doesn't understand the identifier, rather than down the line when it tries
to match up the struct.

However I'm surprised that a German should make an error in use of capitals.
 
H

Hanno Boettcher

Malcolm said:
This is an argument for typedefing your structs.

typedef struct
{
int x;
/* blah */
}GitterPunkt.

Now if you type

Gitterpunkt *ptr;

the compiler should tell you that the declaration is invalid because it
doesn't understand the identifier, rather than down the line when it tries
to match up the struct.

However I'm surprised that a German should make an error in use of capitals.
Even Germans aren't perfect :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top