Initialize and print 128-bit integers in C
Read OriginalThis article addresses the challenge of initializing and printing 128-bit integers in C, specifically with GCC and Clang compilers. It highlights that C compilers cannot parse 128-bit integer literals directly, causing errors. The author provides a solution using a macro `U128(hi, lo)` that combines two 64-bit values via bit shifting and OR operations. Additionally, it covers printing 128-bit integers with a custom `print_u128` function, handling cross-compiler warnings by using `inttypes.h` and `PRIx64` format specifiers. The final code compiles cleanly on both GCC and Clang, offering a practical guide for developers working with extended integer types.
Comments
No comments yet
Be the first to share your thoughts!
Browser Extension
Get instant access to AllDevBlogs from your browser
Top of the Week
No top articles yet