简体   繁体   中英

Declaration of wchar_t by myself

Please tell me, where can I find the wchar_t declaration. I use linux, and I think it is 32 bits. 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. Also what about mbstate_t?

You don't need to go to the files containing the definition of wchar_t.
In the standard header stdint.h it can be found the information about integer types in your particular implementation.

For example, the constants WCHAR_MIN and WCHAR_MAX bring information about the range of values of wchar_t .

On the ohter hand, if WCHAR_MIN == 0 , then wchar_t is an unsigned integer type . Else, it's a signed integer type (in this case it would prefirable to check the condition 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) .

If you are not using the standard library, then you do not need wchar_t . Or at least the standard library's idea of wchar_t doesn't matter to you. 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. In particular, wchar_t is not a characteristic of any system; rather, it is a characteristic of a particular C library. Different C libraries for the very same system, including yours, can freely define it differently. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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