J
javadesigner
Hi:
I am a bit new to C programming and am trying to
write a wrapper around malloc. Since malloc takes
size_t as it's parameter, I want to be able to
see if my function recieved an argument less than
or equal to the max size_t type.
So:
//my wrapper function mallocstr
char * mallocstr(size_t num)
{
//TEST
if (CODE HERE TO TEST FOR num <= max size of size_t) {
printf("some debug error message\n");
return NULL;
}
//END TEST
return (char *) malloc(num);
}
Now, ignore the fact that malloc will return NULL if
unsucessful and I may not need the test. If I _do_
want to structure my code in the above fashion, is there
any _way_ to do it ?
I.E., replace the "CODE HERE..." line with some
test that can tell me with my argument was less than
of equal to the max size of the size_t type.
I am on a gcc system and would like to do this portably.
As far as I can tell, there is no gcc defined macro
or any value in limit.h that tells me the max size of
size_t.
Maybe I am missing something, but this appears tougher
than it should be.
Best regards,
--j
I am a bit new to C programming and am trying to
write a wrapper around malloc. Since malloc takes
size_t as it's parameter, I want to be able to
see if my function recieved an argument less than
or equal to the max size_t type.
So:
//my wrapper function mallocstr
char * mallocstr(size_t num)
{
//TEST
if (CODE HERE TO TEST FOR num <= max size of size_t) {
printf("some debug error message\n");
return NULL;
}
//END TEST
return (char *) malloc(num);
}
Now, ignore the fact that malloc will return NULL if
unsucessful and I may not need the test. If I _do_
want to structure my code in the above fashion, is there
any _way_ to do it ?
I.E., replace the "CODE HERE..." line with some
test that can tell me with my argument was less than
of equal to the max size of the size_t type.
I am on a gcc system and would like to do this portably.
As far as I can tell, there is no gcc defined macro
or any value in limit.h that tells me the max size of
size_t.
Maybe I am missing something, but this appears tougher
than it should be.
Best regards,
--j