Monday, September 22, 2008

I was wondering how to tell whether a given typedef was a signed or unsigned integral type (e.g. unsigned int vs signed int, size_t vs ssize_t, etc.) in C. In C++ it would be easy with a little bit of meta-programing but in C there are far fewer options when it comes to static (aka compile-time) checking. And on this one, Google didn't help me much. So I thought I'd write something, hopefully it'll be helpful to someone searching what I was trying to find.

4 comments:

So If I translate the previous comment via Google's language tools, it (approximately) reads:"If I were to char and the value of the OR for 0xffffff computing, and then detect whether or not less than 0, can not know whether this char for unsigned or signed it?Xiangliaoyixiang 1:00 am sorry, did not write a small program Test"

To which I'd answer that I don't see any benefit especially since 0xffffff is a fixed value and it's not suitable for all numeric data type (some are shorter, some are larger).