oneday oneday - 6 months ago 61
C Question

How to typecast preprocessor (macros) to output int

I have a very simple macro for which I want to typecast its output to

only. How to do that?

#define Numbits(A) (sizeof(A)*CHAR_BIT)

I tried:

#define int Numbits(A)({int val; val = sizeof(A)*CHAR_BIT; return val;})

but it also doesn't work


Are you saying that #define Numbits(A) (int)(sizeof(A)*CHAR_BIT) didn't work?