stdint

Why does everybody typedef over standard C types?

你说的曾经没有我的故事 提交于 2019-11-28 16:46:27
If you want to use Qt , you have to embrace quint8 , quint16 and so forth. If you want to use GLib , you have to welcome guint8 , guint16 and so forth. On Linux there are u32 , s16 and so forth. uC/OS defines SINT32 , UINT16 and so forth. And if you have to use some combination of those things, you better be prepared for trouble. Because on your machine u32 will be typedef d over long and quint32 will be typedef d over int and the compiler will complain . Why does everybody do this, if there is <stdint.h> ? Is this some kind of tradition for libraries? Edward Karak stdint.h didn't exist back

difference between stdint.h and inttypes.h

牧云@^-^@ 提交于 2019-11-28 15:51:58
What is the difference between stdint.h and inttypes.h? If none of them is used, uint64_t is not recognized but with either of them it is a defined type. See the wikipedia article for inttypes.h. Use stdint.h for a minimal set of definitions; use inttypes.h if you also need portable support for these in printf, scanf, et al. stdint.h Including this file is the "minimum requirement" if you want to work with the specified-width integer types of C99 (i.e. "int32_t", "uint16_t" etc.). If you include this file, you will get the definitions of these types , so that you will be able to use these

difference between stdint.h and inttypes.h

a 夏天 提交于 2019-11-27 19:52:12
问题 What is the difference between stdint.h and inttypes.h? If none of them is used, uint64_t is not recognized but with either of them it is a defined type. 回答1: See the wikipedia article for inttypes.h. Use stdint.h for a minimal set of definitions; use inttypes.h if you also need portable support for these in printf, scanf, et al. 回答2: stdint.h Including this file is the "minimum requirement" if you want to work with the specified-width integer types of C99 (i.e. "int32_t", "uint16_t" etc.).

Reasons to use (or not) stdint

心不动则不痛 提交于 2019-11-27 17:36:08
I already know that stdint is used to when you need specific variable sizes for portability between platforms. I don't really have such an issue for now, but what are the cons and pros of using it besides the already shown fact above? Looking for this on stackoverflow and others sites, I found 2 links that treats about the theme: codealias.info - this one talks about the portability of the stdint. stackoverflow - this one is more specific about uint8_t . These two links are great specially if one is looking to know more about the main reason of this header - portability . But for me, what I

Why does everybody typedef over standard C types?

廉价感情. 提交于 2019-11-27 09:54:26
问题 If you want to use Qt, you have to embrace quint8 , quint16 and so forth. If you want to use GLib , you have to welcome guint8 , guint16 and so forth. On Linux there are u32 , s16 and so forth. uC/OS defines SINT32 , UINT16 and so forth. And if you have to use some combination of those things, you better be prepared for trouble. Because on your machine u32 will be typedef d over long and quint32 will be typedef d over int and the compiler will complain . Why does everybody do this, if there

Why is the maximum size of an array “too large”?

半腔热情 提交于 2019-11-27 04:56:56
I'm under the same impression as this answer , that size_t is always guaranteed by the standard to be large enough to hold the largest possible type of a given system. However, this code fails to compile on gcc/Mingw: #include <stdint.h> #include <stddef.h> typedef uint8_t array_t [SIZE_MAX]; error: size of array 'array_t' is too large Am I misunderstanding something in the standard here? Is size_t allowed to be too large for a given implementation? Or is this another bug in Mingw? EDIT: further research shows that typedef uint8_t array_t [SIZE_MAX/2]; // does compile typedef uint8_t array_t

Reasons to use (or not) stdint

♀尐吖头ヾ 提交于 2019-11-27 04:12:26
问题 I already know that stdint is used to when you need specific variable sizes for portability between platforms. I don't really have such an issue for now, but what are the cons and pros of using it besides the already shown fact above? Looking for this on stackoverflow and others sites, I found 2 links that treats about the theme: codealias.info - this one talks about the portability of the stdint. stackoverflow - this one is more specific about uint8_t . These two links are great specially if

Why is the maximum size of an array “too large”?

三世轮回 提交于 2019-11-26 12:28:44
问题 I\'m under the same impression as this answer, that size_t is always guaranteed by the standard to be large enough to hold the largest possible type of a given system. However, this code fails to compile on gcc/Mingw: #include <stdint.h> #include <stddef.h> typedef uint8_t array_t [SIZE_MAX]; error: size of array \'array_t\' is too large Am I misunderstanding something in the standard here? Is size_t allowed to be too large for a given implementation? Or is this another bug in Mingw? EDIT:

<cstdint> vs <stdint.h>

我怕爱的太早我们不能终老 提交于 2019-11-26 06:20:36
问题 What is the difference between stdint.h and cstdint ? Both of them are available in MSVC (Visual Studio 2010) and gcc-4.5.1. Also both define the intX_t / uintX_t types (where X is the size in bytes of the type). If the rationale in both headers is the same (portable types), what decisions I must take to decide on one or the other? The stdint.h defines each type without any namespace, the cstdint types lies in the std namespace. Is there any reason to include or to not include the defined

How to print a int64_t type in C

自作多情 提交于 2019-11-25 23:51:59
问题 C99 standard has integer types with bytes size like int64_t. I am using the following code: #include <stdio.h> #include <stdint.h> int64_t my_int = 999999999999999999; printf(\"This is my_int: %I64d\\n\", my_int); and I get this compiler warning: warning: format ‘%I64d’ expects type ‘int’, but argument 2 has type ‘int64_t’ I tried with: printf(\"This is my_int: %lld\\n\", my_int); // long long decimal But I get the same warning. I am using this compiler: ~/dev/c$ cc -v Using built-in specs.