GCC warnings question

Nathan Sidwell nathan@codesourcery.com
Tue Apr 13 14:02:00 GMT 2004


Jonathan Wilson wrote:
> Is there a way to turn off these 2 warnings:
> warning: dereferencing type-punned pointer will break strict-aliasing rules
> warning: `xxx' defined but not used
> without turning anything else off?
> 
> And also, what does the first warning mean?
it means that code looks like you might be trying to do
	foo (int *ptr)
	{
	 short *first = (short *)ptr;
	 short s;

	 *ptr = 1;
	 s = *first;
	}
which is undefined.

turn #1 off by casting via void
	(short *)(void *)ptr
This does not change the undefinedness of your code.

turn #2 off with
	int xxx __attribute((unused));

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk




More information about the Gcc mailing list