oneday oneday - 1 year ago 138
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download