CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2009
    Posts
    8

    typedef struct of struct

    I'm trying to use some structs from something I didn't make. They're defined as follows:
    Code:
    typedef struct Pxy_t {
        double x, y;
    } Pxy_t;
    typedef struct Pxy_t Ppoint_t;
    and somehow I need to give a Ppoint_t to a function.
    They show a sample, initializing
    Code:
    static Ppoint_t ps[] = {
        { 1.0, 2.5 },
        { 4.7, 3.2 }
    };
    and feed ps to the function.
    But I'm looking to fill these values in dynamically, but I can't figure out for the life of me how to declare an equivalent to ps. Everything I've tried results in "Ppoint_t: illegal use of this type as an expression." The function declaration lists "Ppoint_t endpoints[2]," but that doesn't work either. I've also never seen typedef struct A B where A is a struct declared as typedef struct A {} A;

    strange to me!

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: typedef struct of struct

    Basically, you want to create a dynamic array of Ppoint_t? If so, you would use a std::vector<Ppoint_t> in C++ or a pointer to Ppoint_t and malloc(), calloc(), realloc() and free() in C.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jul 2009
    Posts
    8

    Re: typedef struct of struct

    Ppoint_t* ps;

    "'Ppoint_t' : illegal use of this type as an expression "

    maybe something else is going on here, hmmm

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: typedef struct of struct

    Okay, state whether you are programming in C or C++, then provide the smallest and simplest program that demonstrates the error.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Jul 2009
    Posts
    8

    Re: typedef struct of struct

    Hi,
    Well you definitely put me in the right direction. Thanks!
    This was actually for compilation of a MEX file for matlab, which unbeknownst to me invoked c, so my variable declaration halfway through code wasn't allowed. Bingo!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured