Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MorphingDragon

macrumors 603
Original poster
Mar 27, 2009
5,159
6
The World Inbetween
I'm making some C code to work with SVG Vector Sprites.

I have done all the planning on paper on how to read the SVG File, represent the paths, path styles, OpenGL\Quartz2D\GDI drawing etc and how to store them into an array.

I want to have a single struct to hold the points for the paths, styles and matrix transformation.

Basically I have 3 arrays. A void-ptr array for the paths and path symbols. A void-ptr array to hold the styles for the paths. An int array to hold the matrix transformation for the paths.

What I don't know is, when declaring the struct, do I have a single pointer for the array, or do I have a pointer to a pointer. (The array's size wont be known when the struct is declared, made)
 
Last edited:
I'm making some C code to work with SVG Vector Sprites.

I have done all the planning on paper on how to read the SVG File, represent the paths, path styles, OpenGL\Quartz2D\GDI drawing etc and how to store them into an array.

I want to have a single struct to hold the points for the paths, styles and matrix transformation.

Basically I have 3 arrays. A void-ptr array for the paths and path symbols. A void-ptr array to hold the styles for the paths. An int array to hold the matrix transformation for the paths.

What I don't know is, when declaring the struct, do I have a single pointer for the array, or do I have a pointer to a pointer. (The array's size wont be known when the struct is declared, made)

I'm not sure I fully understand the situation, but if the question is just "how do I declare a member variable to a struct which is a variable length array?" then the answer is as a single pointer (not a pointer to a pointer). When you do know the length of the array, simply allocate a portion of memory of that length, and point the pointer to it (mystruct.array = (void *)malloc( num_bytes );)
 
If you have several fixed-size elements and one variable size array, you could declare that array as the last element in the struct, eg,

Code:
typedef struct 
{
int somePts[32];
char *lblStrings[32];
void *sprites[0];
} dStruct;
in which case, the sprites array would fall completely outside the bounds of the struct: you would have to formulate an allocation something like
Code:
malloc( sizeof( dStruct ) + ( sizeof( void* ) * spriteCount ) );

I believe you will find it handier to simply create an array of structs. Create a struct that can hold as much atomic data as practical (never too little) and array them. You might waste some space, but it might be easier to work with.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.