Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Galileo430

Memory Allocation in ANSI C

This topic is 6499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writeing a game app ment to run on a UNIX server so I have to use ANSI C. Everytime malloc expects a constant expressions. Anyone know a command that doesn''t?

Share this post


Link to post
Share on other sites
Advertisement
malloc should be able to take a non-constant argument. How exactly are you using malloc, and what error are you getting?

Share this post


Link to post
Share on other sites
I''m quite certain either the error is on the line before it, or you''re using an improper syntax while calling the variable. Please post the offending line of code (plus say about 5 lines before & 5 lines after). We can''t tell what''s wrong from the information you''ve given us.

Share this post


Link to post
Share on other sites
Yeah some code would help us here.

i use something like,
int *myInt = (int*)malloc(sizeof(int));

Share this post


Link to post
Share on other sites
nope,

here is the REALY screwy call I have to make.

  
global[nGifNumber]->entry = (struct COLORTABLE *)malloc( sizeof(struct RGBTRIPLET[gdata[nGifNumber].nGCTSize]) );

// Here are the errors I get.

error C2057: expected constant expression
warning C4047: ''='' : ''struct RGBTRIPLET *[1]'' differs in levels of indirection from ''struct COLORTABLE *''
error C2106: ''='' : left operand must be l-value



Remind me to hurt compuserve very much for their wonderful GIF format..

Share this post


Link to post
Share on other sites
I''m a mite confused at what you''re calculating the sizeof()...but I think that you''ve got a structure defined called RGBTRIPLET - have you typedef''ed it something like this ?

typedef struct {
BYTE r, g, b;
} RGBTRIPLET;

If you have I think what you should do is:
  
global[nGifNumber]->entry = (struct COLORTABLE *)malloc( ( sizeof(RGBTRIPLET) * gdata[nGifNumber].nGCTSize );


If when you typedef''ed the RGBTRIPLET (it''s not a standard typedef is it ?) you should have the name at the end, if you haven''t, then IMO you aught to do it as I illustrated at the top of this post

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!