• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
flexible array member not initializing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

flexible array member not initializing


  • Subject: flexible array member not initializing
  • From: Juan Vesa <email@hidden>
  • Date: Mon, 5 Apr 2010 23:21:58 +1000

hello,
sorry if this is not ok topic for this list.
i'm writing a program in xcode 2.4.1, os x 10.4.11, ndi have a struct Object like:

typedef struct Object
{
char* filename;
//internal index for reading vertex position
int i; 
p_ply ply;
long nvertices;
long nfaces;
Vertex* vertices[];
} Object;

when i initialize it in a newobject() function, all the member get initialized except for the array vertices, i'm using dynamic allocation in the newobject() method like:

Object* newo=(Object*)malloc(sizeof(Object)+sizeof(Vertex)*nverts);
if (newo==NULL) {
return NULL;
}

where nverts is the size of an array (read in from a file at run time), and vertex is another structure with 3 double member values. so looking to the debugger all the data members are there but vertices doesn't exist, so later when trying to use an Object struct allocated by this method in another function i can't add anything to the array vertices, the debugger comes up and i get the error "Program received signal:  "EXC_BAD_ACCESS".".

o->vertices[o->i]->x = value;

could any one please help? the entire newobject() function is below.
thank you very much,
juan

Object* newobject(char* filename, long nverts, long nface, p_ply ply)
{
Object* newo=(Object*)malloc(sizeof(Object)+sizeof(Vertex)*nverts);
if (newo==NULL) {
return NULL;
}
newo->i = 0;
newo->filename = filename;
newo->nvertices = nverts;
newo->nfaces = nface;
newo->ply = ply;
newo->vertices[0] = NULL;
return newo;
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: flexible array member not initializing
      • From: Douglas Norton <email@hidden>
    • Re: flexible array member not initializing
      • From: Vladimir Zidar <email@hidden>
  • Prev by Date: Re: Silencing deprecation warnings
  • Next by Date: Re: flexible array member not initializing
  • Previous by thread: Re: Silencing deprecation warnings
  • Next by thread: Re: flexible array member not initializing
  • Index(es):
    • Date
    • Thread