Hello all,
I've got a warning coming up in some code that I don't understand (the subject line should tell you what it is).
The lines in question are implementations of the following macros that I've written as a very simple mechanism for code to exit gracefully in the event of a memory allocation error. Here are the macros:
So, for example, in the program one would type,
These macros appear to work fine and it's only on one occasion when the warning message is generated: when the "vectorsize" entry is a const int set equal to 1000000.
I really, really would like this int to be 1000000. So, what's the issue? Should I set it to long int? Or is there something else I should be aware of?
Many thanks,
-- Joe
P.S. if the macros are useful, feel free to use. If they're crap, advice on what would be good is appreciated.
I've got a warning coming up in some code that I don't understand (the subject line should tell you what it is).
The lines in question are implementations of the following macros that I've written as a very simple mechanism for code to exit gracefully in the event of a memory allocation error. Here are the macros:
Code:
#define MALLOC(vector,vectorsize,vectortype,errmessage) { vectortype *temp = (vectortype *)malloc((unsigned) (vectorsize)*sizeof(vectortype)); if(temp!=NULL) vector = temp; else error_output_quit(errmessage); }
#define CALLOC(vector,vectorsize,vectortype,errmessage) { vectortype *temp = (vectortype *)calloc((unsigned) (vectorsize), (unsigned) sizeof(vectortype)); if(temp!=NULL) vector = temp; else error_output_quit(errmessage); }
#define REALLOC(vector,oldvector,vectorsize,vectortype,errmessage) { vectortype *temp = (vectortype *)realloc(oldvector,(unsigned) (vectorsize)*sizeof(vectortype)); if(temp!=NULL) vector = temp; else error_output_quit(errmessage); }
So, for example, in the program one would type,
Code:
MALLOC(x,100,double,"If this error message is produced, malloc'ing x failed");
These macros appear to work fine and it's only on one occasion when the warning message is generated: when the "vectorsize" entry is a const int set equal to 1000000.
I really, really would like this int to be 1000000. So, what's the issue? Should I set it to long int? Or is there something else I should be aware of?
Many thanks,
-- Joe
P.S. if the macros are useful, feel free to use. If they're crap, advice on what would be good is appreciated.