-
December 20th, 2009, 04:02 AM
#1
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!
-
December 20th, 2009, 04:27 AM
#2
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.
-
December 20th, 2009, 04:30 AM
#3
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
-
December 20th, 2009, 04:38 AM
#4
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.
-
December 20th, 2009, 01:39 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|