#if typedef() [英] #if typedef()

查看:150
本文介绍了#if typedef()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法知道是否有给定名称的typedef?


具体来说,我需要知道编译器是否有64位整数类型,

并且需要知道是否int64_t存在。类似这样的伪代码:


#if typedef(int64_t)

typedef int64_t MY_BIG_INT

#elif typedef(long long )

typedef long long MY_BIG_INT

#else

typedef long MY_BIG_INT

#endif


(是的,这个程序需要在没有64位
整数的系统上工作,如果它们存在,它需要利用它们。)


此外,包含int64_t typedef需要具有

的标准包含文件是什么?我在< stdint.h>中看到了它在一个编译器上

我有,< native.h>另外一个。我没有看到这些标题是这些系统上其他标准标题所包含的这些标题。


-

+ - ------------------------ + -------------------- + ---- ------------------------- +

| Kenneth J. Brody | www.hvcomputer.com | |

| kenbrody / at\spamcop.net | www.fptech.com | #include< std_disclaimer.h> |

+ ------------------------- + -------------- ------ + ----------------------------- +

不要给我发电子邮件:< mailto:Th ************* @ gmail.com>

Is there any way to know if there is a typedef of a given name?

Specifically, I need to know if the compiler has a 64-bit integer type,
and need to know if "int64_t" exists. Something like this pseudo-code:

#if typedef(int64_t)
typedef int64_t MY_BIG_INT
#elif typedef(long long)
typedef long long MY_BIG_INT
#else
typedef long MY_BIG_INT
#endif

(Yes, this program needs to work on systems which don''t have a 64-bit
integers, and it needs to take advantage of them if they are there.)

Also, what is the standard include file which would be needed to have
the int64_t typedef included? I see it in <stdint.h> on one compiler
I have, and <native.h> on another. I don''t see these headers being
included by other standard headers on these systems.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>

推荐答案

在文章< 42 *************** @ spamcop.net>,

Kenneth Brody< ke ****** @clampscop达网络>写道:
In article <42***************@spamcop.net>,
Kenneth Brody <ke******@spamcop.net> wrote:
有没有办法知道是否有给定名称的typedef?
具体来说,我需要知道编译器是否具有64位整数类型,并且需要知道int64_t是否为int64_t。存在。
Is there any way to know if there is a typedef of a given name? Specifically, I need to know if the compiler has a 64-bit integer type,
and need to know if "int64_t" exists.



在C89中没有可移植的方法来测试它(我不够熟悉

和C99一起知道它是否扩展了但是我怀疑没有。)

处理这个的通常方法是有一个元级别测试

是否存在适当的类型或函数并设置

在构造的包含文件中适当地预处理标记

其余代码导入。

-

注意,有骆驼!


There is no portable way to test that in C89 (I''m not familiar enough
with C99 to know if it were extended in that regard, but I suspect not.)
The usual way to handle this is to have a meta level that tests
for the existance of appropriate types or functions and sets
preprocessing tokens appropriately in a constructed include file
that the rest of the code imports.
--
Look out, there are llamas!


Kenneth Brody< ke ****** @ spamcop.net>写道:
Kenneth Brody <ke******@spamcop.net> writes:
有没有办法知道是否有给定名称的typedef?


No.


[snip]

此外,标准包含文件是什么?有包含int64_t typedef吗?我在< stdint.h>中看到了它在一个编译器上
我有,< native.h>另外一个。我没有看到这些系统上的其他标准标题包含这些标题。
Is there any way to know if there is a typedef of a given name?
No.

[snip]
Also, what is the standard include file which would be needed to have
the int64_t typedef included? I see it in <stdint.h> on one compiler
I have, and <native.h> on another. I don''t see these headers being
included by other standard headers on these systems.




在C99中,int64_t在< stdint.h>中定义;但是C99标准不是普遍支持的
。严格来说,int64_t是可选的;只有当实现具有两个'的补码

整数类型且宽度正好为64位且没有填充时,才会定义
。在

练习中,由于C99需要很长时间才能至少64位,所以我会感到惊讶地看到C99实现没有int64_t。


给定C99实现,宏INT64_MAX将在

< stdint.h>中定义。当且仅当int64_t被定义,所以你可以使用

#ifdef INT64_MAX


你可以检查你是否有一个C99实现


#if __STDC_VERSION__> = 199901L


允许使用C99前编译器,但不是必需的,在

中定义int64_t一个特定于实现的标题 - 或者它可以称之为int_64_t,或

它喜欢的任何东西。预处理器中没有办法测试给定头是否存在

。你几乎必须追踪你需要支持的所有实现的细节

,并为每个实现自定义代码




也许最好的方法是使用你自己的< stdint.h> (或更多

正确,stdint.h)标头与C99前编译器一起使用。见

< http://www.lysator.liu.se/c/q8/>公共域实现。


注意__STDC_VERSION__> = 199901L并不一定意味着

< stdint.h>标题*不存在。有些编译器可能会提供

部分C99支持。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< * GT; < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



In C99, int64_t is defined in <stdint.h>, but the C99 standard is not
universally supported. Strictly speaking, int64_t is optional; it
will be defined only if the implementation has a two''s complement
integer type with a width of exactly 64 bits and no padding. In
practice, since C99 requires long long to be at least 64 bits, I''d be
surprised to see a C99 implementation that doesn''t have int64_t.

Given a C99 implementation, the macro INT64_MAX will be defined in
<stdint.h> if and only if int64_t is defined, so you can use
#ifdef INT64_MAX

You can check whether you have a C99 implementation with

#if __STDC_VERSION__ >= 199901L

A pre-C99 compiler is allowed, but not required, to define int64_t in
an implementation-specific header -- or it can call it int_64_t, or
anything it likes. There''s no way in the preprocessor to test whether
a given header exists. You pretty much have to track down the details
for all the implementations you need to support, and write custom code
for each.

Perhaps the best approach is to use your own <stdint.h> (or, more
properly, "stdint.h") header to be used with pre-C99 compilers. See
<http://www.lysator.liu.se/c/q8/> for a public domain implementation.

Note that __STDC_VERSION__ >= 199901L doesn''t necessarily imply that
the <stdint.h> header *doesn''t* exist. Some compilers might provide
partial C99 support.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Walter Roberson写道:
Walter Roberson wrote:

文章< 42 ******* ********@spamcop.net>,
Kenneth Brody< ke ****** @ spamcop.net>写道:

In article <42***************@spamcop.net>,
Kenneth Brody <ke******@spamcop.net> wrote:
有没有办法知道是否存在给定名称的typedef?
Is there any way to know if there is a typedef of a given name?
具体来说,我需要知道编译器是否具有64位整数类型,
并且需要知道是否int64_t存在。
Specifically, I need to know if the compiler has a 64-bit integer type,
and need to know if "int64_t" exists.



在C89中没有可移植的方法来测试它(我对C99不太熟悉,知道它是否在这方面得到了扩展,但是我怀疑没有。)



There is no portable way to test that in C89 (I''m not familiar enough
with C99 to know if it were extended in that regard, but I suspect not.)




我不能依靠C99可用,所以'不是真的相关。

通常处理这个的方法是有一个元级别,测试是否存在适当的类型或函数,并在构造的包含文件中适当地设置预处理标记,其余代码导入。



I can''t depend on C99 being available, so that''s not really relevent.
The usual way to handle this is to have a meta level that tests
for the existance of appropriate types or functions and sets
preprocessing tokens appropriately in a constructed include file
that the rest of the code imports.




好​​吧,我们已经为不同的平台提供了一堆config.h文件

来定义这些东西本机字节顺序(是的,一些部分代码需要

才能知道),是否无效是可用的(我们曾经在平台上运行

没有void类型),需要哪种类型的varargs,依此类推。我想b $ b只是希望避免再次进入。


我想我可能会最终选择假设有一个int64_t键入

除非配置文件定义NO_INT64_T或类似的东西。


-

+ ----- -------------------- + -------------------- + -------- --------------------- +

| Kenneth J. Brody | www.hvcomputer.com | |

| kenbrody / at\spamcop.net | www.fptech.com | #include< std_disclaimer.h> |

+ ------------------------- + -------------- ------ + ----------------------------- +

不要给我发电子邮件:< mailto:Th ************* @ gmail.com>



Well, we already have a bunch of config.h files for different platforms
to define such things native byte order (yes, some parts of the code need
to know that), whether "void" is available (we used to run on platforms
that had no "void" type), which type of varargs are needed, and so on. I
was just hoping to avoid yet another entry.

I guess I''ll probably end up going with "assume there''s an int64_t type
unless the config file defines NO_INT64_T", or something like that.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>


这篇关于#if typedef()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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