简体   繁体   English

自己声明wchar_t

[英]Declaration of wchar_t by myself

Please tell me, where can I find the wchar_t declaration.请告诉我,在哪里可以找到 wchar_t 声明。 I use linux, and I think it is 32 bits.我使用 linux,我认为它是 32 位的。 I need to declarate this type, because i can't use the standart library (it is used in my boot programm).我需要声明这种类型,因为我不能使用标准库(它在我的引导程序中使用)。 The files /usr/include/wchar.h and /usr/include/linux/stddef.h don't contain the declaration of it.文件 /usr/include/wchar.h 和 /usr/include/linux/stddef.h 不包含它的声明。 Also what about mbstate_t?还有 mbstate_t 怎么样?

You don't need to go to the files containing the definition of wchar_t.您不需要转到包含 wchar_t 定义的文件。
In the standard header stdint.h it can be found the information about integer types in your particular implementation.在标准头文件stdint.h ,可以找到有关特定实现中整数类型的信息。

For example, the constants WCHAR_MIN and WCHAR_MAX bring information about the range of values of wchar_t .例如,常量WCHAR_MINWCHAR_MAX带来有关wchar_t值范围的信息。

On the ohter hand, if WCHAR_MIN == 0 , then wchar_t is an unsigned integer type .另一方面,如果WCHAR_MIN == 0 ,则wchar_tunsigned integer type Else, it's a signed integer type (in this case it would prefirable to check the condition WCHAR_MIN < 0 ).否则,它是有signed integer type (在这种情况下,最好检查条件WCHAR_MIN < 0 )。

To know the amount of bytes used to represent a wchar_t object, you have, of course, the expression sizeof(wchar_t) .要知道用于表示wchar_t对象的字节数,当然有表达式sizeof(wchar_t)

If you are not using the standard library, then you do not need wchar_t .如果您不使用标准库,则不需要wchar_t Or at least the standard library's idea of wchar_t doesn't matter to you.或者至少标准库的wchar_t想法与您无关。 How could it?怎么可能? If you want wide character handling then you'll need to write whatever functions are needed for it, and you are free to define and use whatever types are most suitable / convenient for that purpose.如果您想要宽字符处理,那么您需要编写它所需的任何函数,并且您可以自由定义和使用最适合/方便的任何类型。

You probably will need the kernel headers, though, if you intend make system calls.但是,如果您打算进行系统调用,您可能需要内核头文件。 I can't imagine how your boot program could avoid that, or why it would want to do.我无法想象您的引导程序如何避免这种情况,或者为什么要这样做。 Those types you would need for that purpose will be defined among the kernel headers.您为此目的所需的那些类型将在内核头文件中定义。 You will not need kernel headers, either: since the point of your program is to load and start the kernel, it cannot rely on system calls into the kernel to do its job.您也不需要内核头文件:因为您的程序的重点是加载和启动内核,所以它不能依赖对内核的系统调用来完成它的工作。

The bottom line is that since you have to provide everything not available directly from the hardware / firmware -- which does not present a C interface -- no C definitions outside your own code are relevant to you.最重要的是,由于您必须提供硬件/固件无法直接提供的所有内容——它不提供 C 接口——在您自己的代码之外没有任何 C 定义与您相关。 In particular, wchar_t is not a characteristic of any system;特别是wchar_t不是任何系统的特性; rather, it is a characteristic of a particular C library.相反,它是特定 C 库的特征。 Different C libraries for the very same system, including yours, can freely define it differently.同一系统的不同 C 库,包括您的,可以自由地以不同方式定义它。 If you choose to implement your own wide-character functions, there is no advantage whatever to choosing a wchar_t definition drawn from some other C library.如果您选择实现自己的宽字符函数,那么选择从其他C 库中提取的wchar_t定义没有任何优势。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM