在编译时确定字节序的任何方法? [英] Any Method to Determine Endianness at Compile Time ?

查看:96
本文介绍了在编译时确定字节序的任何方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在编译时间确定编译环境的字节顺序,而不是运行时间?我需要一个宏(some_expression),




#if some_expression

#define TARGET_IS_LITTLE_ENDIAN

#else

#define TARGET_IS_BIG_ENDIAN


没办法或某种方式? TIA。

How could I determine the endianness of my compile environment at
compile time, instead of run time? I need a macro ("some_expression"),
i.e.

#if some_expression
#define TARGET_IS_LITTLE_ENDIAN
#else
#define TARGET_IS_BIG_ENDIAN

No way or some way? TIA.

推荐答案

文章< 27 ********************** ************ @ c19g2000prf。 googlegroups.com>,

perry.yuan< pe ******** @ gmail.comwrote:
In article <27**********************************@c19g2000prf. googlegroups.com>,
perry.yuan <pe********@gmail.comwrote:

>如何在编译时确定编译环境的字节顺序,而不是运行时?
>How could I determine the endianness of my compile environment at
compile time, instead of run time?



你不能写一个编译时表达式来确定它,因为

endianness是表示的属性,而不是值,并且

不是可以在编译时检查其表示的对象

时间。


一种解决方案是在以下位置运行程序编译确定

字节顺序的时间,然后输出一个合适的#define到一个文件,然后包含




- 理查德

-

:wq

You can''t write a compile-time expression to determine it, because
endianness is a property of representations, not values, and there
are no objects whose representations can be examined at compile
time.

One solution is to run a program at compile time that determines
the endianness and outputs a suitable #define to a file which
you then include.

-- Richard
--
:wq


" perry.yuan" < pe ******** @ gmail.comwrites:
"perry.yuan" <pe********@gmail.comwrites:

我怎样才能确定编译环境的字节顺序

编译时间,而不是运行时间?我需要一个宏(some_expression)
How could I determine the endianness of my compile environment at
compile time, instead of run time? I need a macro ("some_expression")



通常这样做的一种方法是分两个阶段构建。首先,

编译并运行一个测试程序,测试

实现的字节顺序。然后使用测试程序的输出

来配置要在构建剩余的

程序时定义的宏。

-

我已经在马车上工作了十多年。在那段时间里没有一个转到

。我不再需要它们了。我现在甚至没有使用

休息或继续,当然除了在社交场合。而且我不会被带走。 --Richard Heathfield

One way this is commonly done is to build in two stages. First,
compile and run a test program that tests for the
implementation''s endianness. Then use the test program''s output
to configure macros to be defined while building the rest of the
program.
--
"I''ve been on the wagon now for more than a decade. Not a single goto
in all that time. I just don''t need them any more. I don''t even use
break or continue now, except on social occasions of course. And I
don''t get carried away." --Richard Heathfield


perry.yuan写道:
perry.yuan wrote:

我怎样才能确定编译环境的字节顺序在

编译时间,而不是运行时间?我需要一个宏(some_expression),




#if some_expression

#define TARGET_IS_LITTLE_ENDIAN

#else

#define TARGET_IS_BIG_ENDIAN


没办法或某种方式? TIA。
How could I determine the endianness of my compile environment at
compile time, instead of run time? I need a macro ("some_expression"),
i.e.

#if some_expression
#define TARGET_IS_LITTLE_ENDIAN
#else
#define TARGET_IS_BIG_ENDIAN

No way or some way? TIA.



这是comp.lang.c中的问题10.16。经常

问答(FAQ)列表< http:// www。 c-faq.com/> ;.你已经在这个新闻组周围花了很长时间才看到

常见问题解答提到了好几十次;对你感到羞耻

没有打扰阅读它。


-
Er ********* @ sun.com


这篇关于在编译时确定字节序的任何方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆