stdint

Casting uint32_t to int32_t and comparing them afterwards

假装没事ソ 提交于 2021-01-27 04:24:49
问题 I'm having trouble understanding how does comparing two ints, where one is unsigned int32 and the other one signed int32 work. Let's consider this simple program: #include <stdint.h> int main() { uint32_t a1 = UINT32_MAX; int32_t b1 = (int32_t)a1; if (a1 == b1) printf("Equal"); else printf("Not equal"); return 0; } In this case, a1 exceeds a signed 32-bit integer range, so as I have confirmed while debugging, after it's been casted, b1 equals -1 . However it still prints "Equal", while those

Is there a portable way to know if uintptr_t is defined in stdint.h?

こ雲淡風輕ζ 提交于 2019-12-23 20:34:13
问题 Preamble: I want to convert a pointer to an integer type, e.g. to check alignment. uintptr_t seems to be the correct type, but it is guaranteed only in C, not in C++ (or C++11) For the following code: #include <stdint.h> #ifndef I_WONDER_IF_UINTPR_T_IS_DEFINED typedef unsigned long uintptr_t; #endif template <typename T> bool isAligned(unsigned char* p) ///Checks alignment with respect to some data type { return !((uintptr_t) p % sizeof(T)); } template bool isAligned<uint16_t>(unsigned char*

using stdint with swig and numpy.i

谁都会走 提交于 2019-12-22 10:57:17
问题 I'm developing a module for using c inline in Python code based on swig . For that I would like to make numpy arrays accessible in C . Until now I used C types like unsigned short but I would like to use types like uint16_t from stdint.h to be save whatever compiler my module encounters. Unfortunately the c++ -functions do not get wrapped correctly when using stdint.h types. The Error given is: _setc() takes exactly 2 arguments (1 given) . That means, the function is not wrapped to accept

uint32_t vs uint_fast32_t vs uint_least32_t

夙愿已清 提交于 2019-12-20 09:48:41
问题 I saw different types of definition of an integer in stdint.h . I'll take unsigned 32-bit integer as an example. uint32_t means clearly an unsigned integer of 32 bits. That's the one I always use. uint_fast32_t and uint_least32_t : What's the difference with uint32_t and when should I use them instead of uint32_t ? And now, I saw uintX_t where X is 24, 40, 48 and 56. It happens in my code that I have to work with 48 and 56-bit integers. As an example, I suppose uint24_t is define as something

Fastest integer type for common architectures

断了今生、忘了曾经 提交于 2019-12-18 12:19:14
问题 The stdint.h header lacks an int_fastest_t and uint_fastest_t to correspond with the {,u}int_fastX_t types. For instances where the width of the integer type does not matter, how does one pick the integer type that allows processing the greatest quantity of bits with the least penalty to performance? For example, if one was searching for the first set bit in a buffer using a naive approach, a loop such as this might be considered: // return the bit offset of the first 1 bit size_t find_first

Why Microsoft Visual Studio cannot find <stdint.h>? [duplicate]

守給你的承諾、 提交于 2019-12-18 05:49:28
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Visual Studio support for new C / C++ standards? See the text below from wiki: The C99 standard includes definitions of several new integer types to enhance the portability of programs[2]. The already available basic integer types were deemed insufficient, because their actual sizes are implementation defined and may vary across different systems. The new types are especially useful in embedded environments

How should the [u]int_fastN_t types be defined for x86_64, with or without the x32 ABI?

梦想的初衷 提交于 2019-12-10 15:13:29
问题 The x32 ABI specifies, among other things, 32-bit pointers for code generated for the x86_64 architecture. It combines the advantages of the x86_64 architecture (including 64-bit CPU registers) with the reduced overhead of 32-bit pointers. The <stdint.h> header defines typedefs int_fast8_t , int_fast16_t , int_fast32_t , and int_fast64_t (and corresponding unsigned types uint_fast8_t et al), each of which is: an integer type that is usually fastest to operate with among all integer types that