The following defines A
to be replaced by B
:
#define A B
Whereas this defines A
to be an alias for the type B
:
typedef B A;
Why ? Isn't this incoherent ?
George Kelly Barnes (July 18, 1895 – July 18, 1954), better known by his pseudonym "Machine Gun Kelly", was an American gangster from Memphis, Tennessee, active during the Prohibition era. His nickname came from his favorite weapon, a Thompson submachine gun.
Colson Baker (born April 22, 1990), known professionally as Machine Gun Kelly (MGK), is an American rapper, singer, songwriter, and actor. He is noted for his genre duality across alternative rock with hip hop. Houston, Texas, U.S. Cleveland, Ohio, U.S.
Simply put: consider the following variable declarations:
// declare a variable called "myInt" with type int
int myInt;
// declare a variable called "myDouble" with type double
double myDouble;
// declare a variable called "myLong" with type long
long myLong;
// declare a variable called "myFunc" with type pointer to function
void (*myFunc)(char*);
Then the typedef
s make perfect sense:
// declare a type alias called "myInt" with type int
typedef int myInt;
// declare a type alias called "myDouble" with type double
typedef double myDouble;
// declare a type alias called "myLong" with type long
typedef long myLong;
// declare a type alias called "myFunc" with type pointer to function
typedef void (*myFunc)(char*);
Macros, on the other hand, can take on a function-style syntax:
#define A(B, C) B, C
A(1, 2) // expands out to 1, 2
So for macros, the "definition" coming after the "name" makes more sense.
(This applies to C++ too, by the way.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With