* Using __BYTE_ORDER without endian.h
@ 2015-06-22 6:57 Rafał Miłecki
2015-06-22 7:07 ` Jens Gustedt
0 siblings, 1 reply; 2+ messages in thread
From: Rafał Miłecki @ 2015-06-22 6:57 UTC (permalink / raw)
To: musl
Hi,
So far we were using uClibc in OpenWrt and my following code was working fine:
#include <byteswap.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#if __BYTE_ORDER == __BIG_ENDIAN
#define cpu_to_le32(x) bswap_32(x)
#define le32_to_cpu(x) bswap_32(x)
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#define cpu_to_le32(x) (x)
#define le32_to_cpu(x) (x)
#else
#error "Unsupported endianness"
#endif
Unfortunately is is *silently* broken with musl. When using musl and
not including endian.h directly the condition:
#if __BYTE_ORDER == __BIG_ENDIAN
is always true.
Could you fix this?
I expect either:
1) __BYTE_ORDER to be always available & set correctly
2) Compile error because of __BYTE_ORDER being undefined
I think such silent miscompilation is sth that has to be avoided.
--
Rafał
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Using __BYTE_ORDER without endian.h
2015-06-22 6:57 Using __BYTE_ORDER without endian.h Rafał Miłecki
@ 2015-06-22 7:07 ` Jens Gustedt
0 siblings, 0 replies; 2+ messages in thread
From: Jens Gustedt @ 2015-06-22 7:07 UTC (permalink / raw)
To: musl; +Cc: Rafał Miłecki
[-- Attachment #1: Type: text/plain, Size: 1584 bytes --]
Am Montag, den 22.06.2015, 08:57 +0200 schrieb Rafał Miłecki:
> Hi,
>
> So far we were using uClibc in OpenWrt and my following code was working fine:
>
> #include <byteswap.h>
> #include <errno.h>
> #include <stdint.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <unistd.h>
>
> #if __BYTE_ORDER == __BIG_ENDIAN
> #define cpu_to_le32(x) bswap_32(x)
> #define le32_to_cpu(x) bswap_32(x)
> #elif __BYTE_ORDER == __LITTLE_ENDIAN
> #define cpu_to_le32(x) (x)
> #define le32_to_cpu(x) (x)
> #else
> #error "Unsupported endianness"
> #endif
>
> Unfortunately is is *silently* broken with musl. When using musl and
> not including endian.h directly the condition:
> #if __BYTE_ORDER == __BIG_ENDIAN
> is always true.
This is correct behavior. Identifiers that are unknown to the
preprocessor always evaluate to 0 and 0 == 0 is true.
> Could you fix this?
>
> I expect either:
> 1) __BYTE_ORDER to be always available & set correctly
> 2) Compile error because of __BYTE_ORDER being undefined
>
> I think such silent miscompilation is sth that has to be avoided.
You should fix your erroneous code by prefixing with something like
#if !defined(__BYTE_ORDER) && !defined(__BIG_ENDIAN)
Jens
--
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536 ::
:: :::::::::::::::::::::: gsm France : +33 651400183 ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-06-22 7:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-22 6:57 Using __BYTE_ORDER without endian.h Rafał Miłecki
2015-06-22 7:07 ` Jens Gustedt
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).