CountBitsM syntax: This macro has one parameter and produces a value of type int. There is no prototype (since macros are never prototyped).
Parameters: objectOrType – any expression with an object data type (24, temp, printf("Hello"), etc.), or the literal name of any object data type (int, float, double, etc.)
Synopsis: Determines the number of bits of storage used for the data type of objectOrType on any machine on which it is run. This is an extremely trivial macro.
Return: the number of bits of storage used for the data type of objectOrType.
CountBitsM must:
not assume a char/byte contains 8 or any other specific number of bits;
not call any function;
not use any external variables;
not perform any right-shifts;
not display anything.
not use any variables;
use a macro from header file limits.h
How can I create Macro Function in header file named "CountBitsM"?
As the assignment says: There is no prototype (since macros are never prototyped).
use a macro from header file limits.h
You haven't done this.
You're printing the result of CountBitsM() as if it's an int (%d). You should make it an unsigned long (%ld). On a 64-bit system, an object's size can exceed the max value of int. Bugs like this are the reason that you could use cout instead of printf().
Macros are different from functions. They are not "called" the way a function is. Instead, the text of the macro is expanded and inserted where you put it.
A macro is nothing more than a "copy-and-replace" program that you would see in places like Microsoft Word. It literally just replaces all occurrences of the macro with the body, wherever you use it. Like "find-and-replace".