T
temper3243
1) According to this
http://prokutfaq.byethost15.com/FindSizeWithoutSizeof
size_t size_type = (char*)((type*)0 + 1) - (char*)(type*)0;
Does this work for void type ? sizeof(void) is undefined but here we
get size of void * as
sizeof void.
int main()
{
size_t size=(char*)((int*)0 + 1) - (char*)(int*)0;
printf("Size of int = %u\n",size);
return 0;
}
Is this code correct ? We are subtracting pointers that are not within
the array.Undefined behaviour or
implementation defined ?
2) According to standard freeing a pointer twice (not setting it to
NULL after first free) allocated
by malloc is undefined behaviour. Why ? Shouldn't it be implementation
defined .
What if there is a implementation where #define free(p) do{\
libfree(p);p=NULL; \} while(0);
What if a free(p) that frees after sometime 10 ms
a) where it actually counts the number of frees to that pointer and
then frees it once
http://prokutfaq.byethost15.com/FindSizeWithoutSizeof
size_t size_type = (char*)((type*)0 + 1) - (char*)(type*)0;
Does this work for void type ? sizeof(void) is undefined but here we
get size of void * as
sizeof void.
int main()
{
size_t size=(char*)((int*)0 + 1) - (char*)(int*)0;
printf("Size of int = %u\n",size);
return 0;
}
Is this code correct ? We are subtracting pointers that are not within
the array.Undefined behaviour or
implementation defined ?
2) According to standard freeing a pointer twice (not setting it to
NULL after first free) allocated
by malloc is undefined behaviour. Why ? Shouldn't it be implementation
defined .
What if there is a implementation where #define free(p) do{\
libfree(p);p=NULL; \} while(0);
What if a free(p) that frees after sometime 10 ms
a) where it actually counts the number of frees to that pointer and
then frees it once