Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #41155
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: String integer id |
| Date | 2016-02-23 09:16 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <nah4ak$hl6$1@dont-email.me> (permalink) |
| References | (3 earlier) <874md0uz5w.fsf@bsb.me.uk> <a0503ba6-bfe4-4c63-85bf-758322db04f3@googlegroups.com> <nagaf3$gol$2@jstuckle.eternal-september.org> <nagcau$n0j$1@dont-email.me> <nagcrj$nvc$1@jstuckle.eternal-september.org> |
On 23/02/16 02:35, Jerry Stuckle wrote:
> On 2/22/2016 8:26 PM, Alf P. Steinbach wrote:
>> On 23.02.2016 01:54, Jerry Stuckle wrote:
>>> On 2/22/2016 6:16 PM, Öö Tiib wrote:
>>>>
>>>> There are no standard trick neither in C nor in C++ to determine
>>>> endianness compile time. Any type punning is forbidden in 'constexpr'
>>>> functions. For practical purposes Boost header file endian.hpp covers
>>>> endianness for large amount of platforms.
>>>>
>>>
>>> Wrong again.
>>
>> Öö Tiib is correct. There are no known tricks, and absolutely no
>> standard or well known ones. The [1] C FAQ mentions a possible trick,
>>
> Wrong again. There are ways, using unions. But I'm not going to get
> into an argument with a troll.
>
I would like to know of a reliable, standard way of identifying
endianness at compile time. Bonus points if it works in C too. I don't
believe such a method exists, but you state it with such confidence.
There are plenty of ways of detecting endianness at run-time, and for
many of them compilers can typically optimise the check and
pre-calculate it:
#define I_AM_LITTLE (((union { unsigned x; unsigned char c; }){1}).c)
But such checks are not constant expressions - you cannot use the result
in things like static initialisers, constexpr expressions, static
asserts, #if directives, etc.
Most toolchains have some sort of pre-defined compiler macros or a
header file with macros that can be used to determine endianness (like
gcc's __BYTE_ORDER__ and __ORDER_LITTLE_ENDIAN__, so there are plenty of
implementation-specific methods.
A compile-time constant expression that relies on nothing beyond the
standards would be fascinating - please post it here.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
String integer id malcolm.mclean5@btinternet.com - 2016-02-22 06:59 -0800
Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-22 17:30 +0100
Re: String integer id malcolm.mclean5@btinternet.com - 2016-02-22 09:04 -0800
Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-22 19:03 +0100
Re: String integer id malcolm.mclean5@btinternet.com - 2016-02-22 13:22 -0800
Re: String integer id Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-22 23:02 +0000
Re: String integer id Öö Tiib <ootiib@hot.ee> - 2016-02-22 15:16 -0800
Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 19:54 -0500
Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 02:26 +0100
Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 20:35 -0500
Re: String integer id legalize+jeeves@mail.xmission.com (Richard) - 2016-02-23 02:31 +0000
Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 21:42 -0500
Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 04:59 +0100
Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-23 08:32 -0500
Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 03:34 +0100
Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 21:38 -0500
Re: String integer id Google <google@google.com> - 2016-02-22 19:36 -0800
Re: String integer id David Brown <david.brown@hesbynett.no> - 2016-02-23 09:25 +0100
Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-23 08:33 -0500
Re: String integer id David Brown <david.brown@hesbynett.no> - 2016-02-23 15:43 +0100
Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-23 11:21 -0500
Re: String integer id woodbrian77@gmail.com - 2016-02-22 20:48 -0800
Re: String integer id David Brown <david.brown@hesbynett.no> - 2016-02-23 09:16 +0100
Re: String integer id Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-23 18:23 +0200
Re: String integer id David Brown <david.brown@hesbynett.no> - 2016-02-23 22:29 +0100
Re: String integer id Barry Schwarz <schwarzb@dqel.com> - 2016-02-22 11:41 -0800
Re: String integer id Ian Collins <ian-news@hotmail.com> - 2016-02-23 09:13 +1300
Re: String integer id Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-23 00:32 +0200
Re: String integer id legalize+jeeves@mail.xmission.com (Richard) - 2016-02-22 22:39 +0000
Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 00:46 +0100
Re: String integer id Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-23 10:01 +0200
Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 19:15 +0100
Re: String integer id Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-23 21:40 +0200
Re: String integer id Juha Nieminen <nospam@thanks.invalid> - 2016-02-23 09:18 +0000
Re: String integer id malcolm.mclean5@btinternet.com - 2016-02-23 03:15 -0800
csiph-web