Thread: invalid initializer

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    15

    invalid initializer

    hello!

    i declared these types:
    Code:
    typedef struct fVector2D {
      float x;
      float y;
    }tVector2D;
    
    ...
    
    typedef struct fVector3D {
      float x;
      float y;
      float z;    
    }tVector3D;
    
    ...
    
    typedef struct tDreieck *pDreieck;
    struct tDreieck {
    	unsigned int punkte[3];
    ...
    };
    
    ...
    
    typedef struct koerper{
    ...
          unsigned int anzDreieck;
          pDreieck dreiecke;
          tVector3D *p_punkte;
    ...
    }tKoerper; 
    typedef struct koerper *pKoerper;
    
    ...
    
    typedef struct objekt {
    ...
          pKoerper p_koerper;
    ...
    }tObjekt;
    
    ...
    
    typedef struct szenenGraph *pSzenenGraph;
    struct szenenGraph
    {
      tObjekt objekt;
      pSzenenGraph kind;
      pSzenenGraph prev;
      pSzenenGraph next;
    };
    and im trying this:

    Code:
    void
    zeichneSzenenGraph(pSzenenGraph wurzelzeiger){
    ...
    tVector3D normale = vec3Cross(vec3Sub(wurzelzeiger->objekt.p_koerper->p_punkte[wurzelzeiger->objekt.p_koerper->dreiecke[n].punkte[3]],
                                                               wurzelzeiger->objekt.p_koerper->p_punkte[wurzelzeiger->objekt.p_koerper->dreiecke[n].punkte[2]]),
                                                       vec3Sub(wurzelzeiger->objekt.p_koerper->p_punkte[wurzelzeiger->objekt.p_koerper->dreiecke[n].punkte[1]],
                                                               wurzelzeiger->objekt.p_koerper->p_punkte[wurzelzeiger->objekt.p_koerper->dreiecke[n].punkte[2]]));
    ...
    }
    trying to compile, i get :"invalid initializer"

    can anyone tell me why, please?

    thanks
    martin

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    we really need more info..

    waht is vec3cross? and vec3sub?
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I refuse to read code where they hide pointers. Sorry. It's just too damn ugly.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well peeling away several layers of indirection with a local variable would help
    Code:
    pKoerper *bar = wurzelzeiger->objekt.p_koerper;
    tVector3D normale = vec3Cross(vec3Sub(bar->p_punkte[bar->dreiecke[n].punkte[3]],
                                          bar->p_punkte[bar->dreiecke[n].punkte[2]]),
                                  vec3Sub(bar->p_punkte[bar->dreiecke[n].punkte[1]],
                                          bar->p_punkte[bar->dreiecke[n].punkte[2]]));
    Then my next impression is that you think arrays start at 1, and not 0, because you have this declaration in a struct
    unsigned int punkte[3];
    and your code is trying to access an out-of-range element

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    15
    thank you for your answer salem.
    the problem is, i cannot initialize a variable *bar like you did. i get:
    Code:
    [Warning] initialization from incompatible pointer type
    i tried not to hide my pointers, like quzah suggested, but that didnt do it either.

    >>misplaced
    vec3Cross and vec3Sub return tVector3D.

    any other idea?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well I would assume you would pick the right type for the pointer.

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    15
    >>Well I would assume you would pick the right type for the pointer.
    i did!
    Code:
    pKoerper *bar = wurzelzeiger->objekt.p_koerper;

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I suggest you create a single file containing the bare minimum of declarations and code which compiles with the same error messages, then post that code.

  9. #9
    Registered User
    Join Date
    Dec 2004
    Posts
    15
    thanks guys. i found out myself.
    i forgot to include "vectorOperations.h"...
    hmpf!

    sorry to bother with such a beginner problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. invalid initializer
    By Milhas in forum C Programming
    Replies: 6
    Last Post: 03-30-2008, 04:11 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM