I know C++11 has a type char32_t that is 4 bytes, and I'm wondering if it's possible to implement something similar in C. The program I'm writing needs to have all char arrays be a multiple of 4 bytes.
Any way to create a char of size 32 in ANSI c?
413 views Asked by Steve Bates At
2
How do you plan on working with this data? Will you only be using a single byte within the 32-bit variable, or will you be storing actual 32-bit data within it?
One simple solution would be to create your own abstract data type so you can change it later:
There is a major pitfall with tinkering with
char
related data types though: a lot of libraries and code snippets in assume that achar
is achar
when working with text. If you plan on using string manipulation functions and expect them to work across multiple systems, you always declare strings as arrays ofchar
, and never assigned char
orunsigned char
. The only time you should be usingunsigned char
is if you are working with 8-bit binary data directly and don't want to have to deal with unexpected oddities like sign extension, which will give you funky values if you aren't careful.