Re: help with type-punned warning please
From: David Ford (david+challenge-response_at_blue-labs.org)
Date: 02/26/04
- Next message: David Ford: "Re: help with type-punned warning please"
- Previous message: Vijay Kumar R Zanvar: "Re: help with type-punned warning please"
- In reply to: David Ford: "help with type-punned warning please"
- Next in thread: Vijay Kumar R Zanvar: "Re: help with type-punned warning please"
- Reply: Vijay Kumar R Zanvar: "Re: help with type-punned warning please"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 26 Feb 2004 02:23:52 -0500
On Wed, 25 Feb 2004 23:59:48 -0500, David Ford wrote:
> 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
Just for the curious, I've since changed my sfree() macro to the following:
#define sfree(x) \
({ \
__typeof(&x) T = (&x); \
\
if ( T && *T ) { \
free (*T); \
*T = NULL; \
} \
})
- Next message: David Ford: "Re: help with type-punned warning please"
- Previous message: Vijay Kumar R Zanvar: "Re: help with type-punned warning please"
- In reply to: David Ford: "help with type-punned warning please"
- Next in thread: Vijay Kumar R Zanvar: "Re: help with type-punned warning please"
- Reply: Vijay Kumar R Zanvar: "Re: help with type-punned warning please"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|