找到正确的C型 [英] Finding the correct c type

查看:103
本文介绍了找到正确的C型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在各地C.新型绊脚石最近,我花了很长时间试图获得为size_t 变量接受的输出函数getline()(误导,或许,由<一个href=\"http://stackoverflow.com/questions/735126/are-there-alternate-implementations-of-gnu-getline-interface\">this)只有最终发现 ssize_t供(是的,两个s的)是正确的类型。有所有可能的变量声明的地方?

I keep stumbling across new types in C. Most recently, I spent a long time trying to get a size_t variable to accept the output of getline() (misled, perhaps, by this) only to eventually notice that ssize_t (yes, two s's) is the correct type. Is there a list of all the possible variable declarations somewhere?

推荐答案

有没有所有可能的类型在C列表中,因为有postentially无限许多人(或足够接近无限多)。

There is no list of all possible types in C, because there are postentially infinitely many of them (or close enough to infinitely many).

我建议你从错误的方向接近这一点。了解所有可能的类型不会编程非常有帮助的;你需要知道什么是用于特定目的的哪一种类型。

I suggest you're approaching this from the wrong direction. Knowing all possible types wouldn't be very helpful in programming; what you need to know is which type to use for a given purpose.

有关要呼叫(包括函数getline ),你需要做的第一件事就是看该功能的文档任何功能。

For any function you want to call (including getline) the first thing you need to do is to read the documentation for that function.

有由语言定义的相对较少的类型。有内置的类型,如字符 INT 双击,等等,并有若干由标准库中定义的类型。请教什么像样的C基准或C标准本身。是最新的草案 N1570 。 (这是2011年ISO C标准,这是尚未完全落实的草案。)

There are relatively few types defined by the language. There are built-in types like char, int, double, and so forth, and there are a number of types defined by the standard library. Consult any decent C reference, or the C standard itself. The latest draft is N1570. (This is a draft of the 2011 ISO C standard, which is not yet fully implemented.)

更多类型由二级标准定义。 POSIX可能是最引人注目的。例如, ssize_t供(这对应于为size_t 有符号的类型)被定义POSIX,而不是由ISO C.

More types are defined by secondary standards. POSIX is probably the most notable of these. For example, ssize_t (which is the signed type corresponding to size_t) is defined by POSIX, not by ISO C.

请务必阅读文档,找到了一些什么特点都保证给定类型。例如,为size_t 保证是一个无符号整数类型, time_t的保证是一个算术类型(它可以签署,签名,甚至浮点)。如果你想写可以移植的code,不作任何假设超越的保证。

Be sure to read the documentation to find out just what characteristics are guaranteed for a given type. For example, size_t is guaranteed to be an unsigned integer type, and time_t is guaranteed to be an arithmetic type (it could be signed, unsigned, or even floating-point). If you want to write portable code, don't make any assumptions beyond what's guaranteed.

这篇关于找到正确的C型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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