Thread: syntax error : missing ')' before '{' and dynamic array in struct

  1. #1
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72

    syntax error : missing ')' before '{' and dynamic array in struct

    Im dynamically allocating some memory, but i get the error:
    syntax error : missing ')' before '{'
    I have counted the number of brackets and i cant see why im getting it. Any ideas? is there something im doing that im not allowed to do syntactically?

    Code:
    MALLOC(oObjectData, (sizeof(Objects *)*OINCREMENT));                   // Error here
    for(iObjectSet=0; iObjectSet<OINCREMENT; iObjectSet++)
    	MALLOC(oObjectData[iObjectSet], sizeof(Objects));      // and here
    Also, related to this. The array im allocating is apart of a struct, so if i was to define the array. Will it then work if i do say:

    struct_name.oObjectData[count]

    Only if i make the array in the structure in the malloc function itself (eg MALLOC(struct_name.oObjectData, ...) it doesnt seem to like it.
    Last edited by gazsux; 03-18-2003 at 06:22 PM.

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    What kind of 'malloc' is this? why you write it in uppercase? it's not the 'malloc' from stdlib, I'm quite sure, because the malloc from stdlib receives just one parameter, and to your MALLOC you're passing 2.

    >>MALLOC(oObjectData[iObjectSet], sizeofObjects));
    this shouldn't be:
    Code:
    MALLOC(oObjectData[iObjectSet], sizeofObjects);
    or
    Code:
    MALLOC(oObjectData[iObjectSet], sizeof Objects);
    I really don't understand if sizeofObjects is a variable, or it's a typo and you meant to write sizeof Objects, anyway, look there is an error here, you have one ')' that isn't needed.
    Last edited by Vber; 03-18-2003 at 06:15 PM.

  3. #3
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    bah, sorry forgot this. I got it from a tutorial so my understanding of it isnt all it could be.

    #define MALLOC(s,t) if(((s) = malloc(t)) == NULL) { oops("error: malloc()"); }

    It just uses that to allow for an implicit error check

    also i meant to put sizeof(Objects) where a variable name of a structure. Sorry, but i copied and pasted it frommy code, i dunno where the brackets went cos its in my source :S :$ i'll update my original accordingly
    Last edited by gazsux; 03-18-2003 at 06:22 PM.

  4. #4
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Well, looking again in your code:
    Code:
    MALLOC(oObjectData[iObjectSet], sizeof Objects);
    And the second one, I'm not sure, but try something like that:
    Code:
    MALLOC(oObjectData, sizeof ((Objects *)*OINCREMENT));

  5. #5
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    i think ill just break it back up into its component parts, ie/ use the real malloc. And maybe not run to boards so quickly after struggling to find an error... i figure it'll stop me from making such a prat of myself cheers for your help guys

Popular pages Recent additions subscribe to a feed