I tried to write the following:
#include <stdint.h>
#include <stdlib.h>
void *ptr = malloc(SIZE_MAX);
But the compiler gave me the following warning:
warning: argument 1 value ‘18446744073709551615’ exceeds maximum object
size 9223372036854775807 [-Walloc-size-larger-than=]
That sounds reasonable. But anyway I'd like to allocate an object of the max possible size on the current implementation/arch. There is the macro RSIZE_MAX
defined in the Annex.B(19)
:
__STDC_WANT_LIB_EXT1__
RSIZE_MAX
So I tried the following example:
#define __STDC_WANT_LIB_EXT1__
#include <stdint.h>
#include <stdlib.h>
int main(){
void *ptr = malloc(RSIZE_MAX);
}
But with no effect, the RSIZE_MAX
is not defined. How to use this macro or any other way to verify maximum object size at compile time?