oneday oneday - 3 months ago 32
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

int
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

Answer

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

Comments