M
Myth__Buster
In reference with the below code,
#include <stdlib.h>
#include <stdio.h>
int f(void)
{
printf("\n In f . . . \n");
}
int main(void)
{
int (*p)(void) = malloc(sizeof(int (*)(void)));
return 0;
}
I would like to question about the return type of malloc(calloc, and realloc).
Assume that the above code runs on a machine wherein the data pointers and function pointers are of different sizes. Then, what malloc returns is a function pointer but after casting it to void* while returning(Or, after assigning it to a void* variable internally and returning its value).
Now, isn't malloc giving us the truncated address in the above context? Consider the same question applicable to calloc and realloc when used in such a context.
Cheers,
Raghavan Santhanam
#include <stdlib.h>
#include <stdio.h>
int f(void)
{
printf("\n In f . . . \n");
}
int main(void)
{
int (*p)(void) = malloc(sizeof(int (*)(void)));
return 0;
}
I would like to question about the return type of malloc(calloc, and realloc).
Assume that the above code runs on a machine wherein the data pointers and function pointers are of different sizes. Then, what malloc returns is a function pointer but after casting it to void* while returning(Or, after assigning it to a void* variable internally and returning its value).
Now, isn't malloc giving us the truncated address in the above context? Consider the same question applicable to calloc and realloc when used in such a context.
Cheers,
Raghavan Santhanam