Is it possible to pass types to a macro? Can I pass types like int, char, long to a macro and have them expanded into C source code that include the passed types?
Is it possible to pass types to a macro? Can I pass types like int, char, long to a macro and have them expanded into C source code that include the passed types?
Last edited by G4143; 03-16-2022 at 09:01 PM.
Sure can.
#define DECLARE(type,var) type var
then later
DECLARE(int,foo)
The pre-processor doesn't know about C in particular.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
The pre-processor is infinitely abusable - yes.
Wait till you discover the # and ## operators
Concatenation (The C Preprocessor)
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.