help with type-punned warning please

From: David Ford (david+challenge-response_at_blue-labs.org)
Date: 02/26/04


Date: Wed, 25 Feb 2004 23:59:48 -0500
To: "David Ford" <david+challenge-response@blue-labs.org>

I have a macro that I use across the board for freeing ram. I'd like to
clean up my code so I don't get these warnings.

#define sfree(x) _internal_sfree((void **)&x)
#define _internal_sfree(x) ({ if(x && *x) { free(*x); *x=NULL; } })

void somefunction() {

        char *x = malloc(10);
        int *y = malloc(10);

        sfree(x);
        sfree(y);
}

results in:

warning: dereferencing type-punned pointer will break strict-aliasing
rules

What's the best way of fixing my lack of clue?

Thank you,
David



Relevant Pages

  • Re: help with type-punned warning please
    ... > I have a macro that I use across the board for freeing ram. ... > clean up my code so I don't get these warnings. ... > void somefunction() { ...
    (comp.lang.c)
  • Re: 2.6.0-test9-mm1 (compile stats)
    ... Building fs/adfs: clean ... Building drivers/net: 31 warnings, 0 errors ... Building drivers/media: 1 warnings, 0 errors ... drivers/ide/ide.c:2470: warning: implicit declaration of function ...
    (Linux-Kernel)
  • Re: 2.6.0-test9-mm2 (compile stats)
    ... Building fs/adfs: clean ... Building drivers/net: 31 warnings, 0 errors ... Building drivers/media: 1 warnings, 0 errors ... drivers/ide/ide.c:2470: warning: implicit declaration of function ...
    (Linux-Kernel)
  • Re: 2.6.0-test9-mm3 (compile stats)
    ... Building fs/adfs: clean ... Building drivers/net: 31 warnings, 0 errors ... Building drivers/media: 1 warnings, 0 errors ... drivers/ide/ide.c:2470: warning: implicit declaration of function ...
    (Linux-Kernel)
  • Re: 2.6.0-test10-mm1 (compile stats)
    ... Building fs/adfs: clean ... Building drivers/net: 31 warnings, 0 errors ... Building drivers/media: 1 warnings, 0 errors ... drivers/ide/ide.c:2470: warning: implicit declaration of function ...
    (Linux-Kernel)