[PATCH 3/3] mkfs_vfat: silence errors on BE platforms

Marc Kleine-Budde mkl at pengutronix.de
Fri Nov 6 12:23:26 UTC 2009


Bastian Blank wrote:
> On Fri, Nov 06, 2009 at 12:01:01PM +0100, Marc Kleine-Budde wrote:
>>>>  #define STORE_LE(field, value) \
>>>>  do { \
>>>>  	if (sizeof(field) == 4) \
>>>> -		field = cpu_to_le32(value); \
>>>> +		field = (typeof(field))cpu_to_le32(value);	\
>>> This looks wrong. If sizeof(field)==4, how can cpu_to_le32 not fit in
>>> there? Doesn't cpu_to_le32() return a 32bit value?
>>>
>>> Or am I missing something obviously? (quite possible ;)
>> cpu_to_le32 probably returns a 32bit value, but _always_.
>> Even if "field" is just a 16bit value. Which leads to this warnings.
> 
> But "field" _is_ a 32bit value.

You have to know a little how a compiler works. First it will analyse
the syntax, then it will eliminate dead code.

In the first step it will issue the warning, even if the code will not
be executed. In fact the "field = cpu_to_le32(value);" will only be
executed if field is a 32 bit value.

Imagine this code:

int foo(int a, int b)

if (0) {
	foo(1);
} else {
	foo(1, 2);
}

The compiler would issue a warning that foo() has been called with the
wrong number of arguments, but in fact it will never be called at all.

It's different from:


int foo(int a, int b)

#if 0
	foo(1);
#else
	foo(1, 2);
#endif

then the preprocessor will remove that foo(1) and the compiler will
never see it.

cheers, Marc

-- 
Pengutronix e.K.                         | Marc Kleine-Budde           |
Linux Solutions for Science and Industry | Phone: +49-231-2826-924     |
Vertretung West/Dortmund                 | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686         | http://www.pengutronix.de   |

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20091106/926955ef/attachment.pgp>


More information about the busybox mailing list