Hi all
I have a program which, with inessential details removed,
looks like this:
--
#include <stdlib.h>
#include <stdio.h>
static int punme(void** dat,size_t newsize)
{
void *newdat = realloc(*dat,ne wsize);
if (! newdat) return 1;
*dat = newdat;
return 0;
}
int main (void)
{
char *dat = malloc(30);
int ret = punme((void**)& dat,40);
printf("punme returns %i\n",ret);
return 0;
}
--
My compiler (gcc -Wall -O3) tells me that "typepun.c: 19:
warning: dereferencing type-punned pointer will break
strict-aliasing rules". The code works as expected, ie,
prints that punme returns 0.
Who is the idiot? Me or the compiler?
Many thanks!
Jim
I have a program which, with inessential details removed,
looks like this:
--
#include <stdlib.h>
#include <stdio.h>
static int punme(void** dat,size_t newsize)
{
void *newdat = realloc(*dat,ne wsize);
if (! newdat) return 1;
*dat = newdat;
return 0;
}
int main (void)
{
char *dat = malloc(30);
int ret = punme((void**)& dat,40);
printf("punme returns %i\n",ret);
return 0;
}
--
My compiler (gcc -Wall -O3) tells me that "typepun.c: 19:
warning: dereferencing type-punned pointer will break
strict-aliasing rules". The code works as expected, ie,
prints that punme returns 0.
Who is the idiot? Me or the compiler?
Many thanks!
Jim
Comment