Search code examples
c++sizebytesizeofprimitive

Custom byte size?


So, you know how the primitive of type char has the size of 1 byte? How would I make a primitive with a custom size? So like instead of an in int with the size of 4 bytes I make one with size of lets say 16. Is there a way to do this? Is there a way around it?


Solution

  • Normally you'd just make a struct that represents the data in which you're interested. If it's 16 bytes of data, either it's an aggregate of a number of smaller types or you're working on a processor that has a native 16-byte integral type.

    If you're trying to represent extremely large numbers, you may need to find a special library that handles arbitrarily-sized numbers.