0

I need all bits to 1 on a char size, while I know in C there is limits.h, and vala has int.MAX, I’m not sure of the char size.

How could I find it - a char size - and generate my bitmask for sure, instead of using 0xFFFF ?

Kwaadpepper
  • 516
  • 4
  • 15

2 Answers2

3

apmasell is right, but I don't really like his answer. If you want the size of char (in bytes), you should use sizeof(char) instead of depending on that value in the glib vapi staying the same.

char.MAX, if it existed, wouldn't be 0xff (255), it would be 0x7f (127), but that isn't the right value for a mask since the. From a practical perspective it's probably safe to assume 0xff is the right value, but if you want to be safe you could just use ~((char) 0).

nemequ
  • 16,623
  • 1
  • 43
  • 62
  • Well tank you for theses info, I the mean time i ended up using ```const uchar CHARMAX = 0xFF;```, since this what i was actually looking for. I guess i will now use ```const uchar CHARMAX = ~((uchar) 0);``` – Kwaadpepper Nov 24 '15 at 22:52
  • 1
    FWIW, it would probably be more appropriate to use uint8 instead of uchar. If what you're dealing with isn't actually an unsigned character (and, based on the fact that you're using a bitmask I doubt it is) then you should just use the appropriate integer type. It is common to use char in C because, until C99, it was basically the only way to get a very small integer (smaller than short), but Vala doesn't have that issue. – nemequ Nov 24 '15 at 22:59
2

In Vala, char is one byte. Here is the VAPI declaration:

[IntegerType (rank = 2, min = 0, max = 127)]
public struct char {
apmasell
  • 7,033
  • 19
  • 28