Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making size_t and wchar_t portable?

Tags:

c++

c

size-t

To my understanding the representation of size_t and wchar_t are completely platform/compiler specific. For instance I have read that wchar_t on Linux is now usually 32bit, but on Windows it is 16bit. Is there any way that I can standardize these to a set size (int, long, etc.) in my own code, while still maintaining backwards comparability with the existing standard C libraries and functions on both platforms?

My goal is essentially to do something like typedef them so they are a set size. Is this possible without breaking something? Should I do this? Is there a better way?

UPDATE: The reason I'd like to do this is so that my string encoding is consistent across both Windows and Linux

Thanks!

like image 555
Tyler Avatar asked Oct 06 '10 21:10

Tyler


1 Answers

Sounds like you're looking for C99's & C++0x's <stdint.h>/<cstdint> headers. This defines types like uint8_t, and int64_t.

You can use Boost's cstdint.hpp in the case you don't have those headers.

like image 140
GManNickG Avatar answered Oct 11 '22 16:10

GManNickG