Structs with pointers

Discussion in 'C Programming' started by Hanno Boettcher, Jun 27, 2004.

  1. 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
     
    Hanno Boettcher, Jun 27, 2004
    #1
    1. Advertising

  2. Hanno Boettcher <> wrote:
    >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
    --
    Irrwahn Grausewitz ()
    welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
    clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
    clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
     
    Irrwahn Grausewitz, Jun 27, 2004
    #2
    1. Advertising

  3. In 'comp.lang.c', Hanno Boettcher <> wrote:

    > struct GitterPunkt{

    <...>
    > struct Gitterpunkt *randunten;

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

    <...>

    Check you code one more time: 'GitterPunkt' is not 'Gitterpunkt'. C is case
    sensitive.

    --
    -ed- get my email here: http://marreduspam.com/ad672570
    The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
    FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
     
    Emmanuel Delahaye, Jun 27, 2004
    #3
  4. Emmanuel Delahaye wrote:
    > In 'comp.lang.c', Hanno Boettcher <> wrote:
    >
    >
    >>struct GitterPunkt{

    >
    > <...>
    >
    >> struct Gitterpunkt *randunten;

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

    >
    > <...>
    >
    > Check you code one more time: 'GitterPunkt' is not 'Gitterpunkt'. C is case
    > sensitive.
    >


    AHHH, thx!
    <-- I'm with stupid
     
    Hanno Boettcher, Jun 27, 2004
    #4
  5. Hanno Boettcher

    Malcolm Guest

    "Hanno Boettcher" <> wrote
    >
    > 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.
     
    Malcolm, Jun 27, 2004
    #5
  6. Malcolm wrote:
    > "Hanno Boettcher" <> wrote
    >
    >>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.

    Even Germans aren't perfect :)
    >
    >
     
    Hanno Boettcher, Jun 28, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patricia  Van Hise

    structs with fields that are structs

    Patricia Van Hise, Apr 5, 2004, in forum: C Programming
    Replies:
    5
    Views:
    650
    Al Bowers
    Apr 5, 2004
  2. Chris Hauxwell

    const structs in other structs

    Chris Hauxwell, Apr 23, 2004, in forum: C Programming
    Replies:
    6
    Views:
    564
    Chris Hauxwell
    Apr 27, 2004
  3. Paminu
    Replies:
    5
    Views:
    651
    Eric Sosman
    Oct 11, 2005
  4. Daniel Rudy
    Replies:
    15
    Views:
    1,421
    Keith Thompson
    Apr 10, 2006
  5. Tuan  Bui
    Replies:
    14
    Views:
    490
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page