Can a macro remove characters from its arguments?

Well, at least it should print "Object"...

//can this be defined?  
#define MACRO(o) #o "\b \b"

int main(){
    printf(MACRO(ObjectT)); //prints "Object" not "ObjectT"
}

And no, you can't strip character using preprocessor only without actual C code (say, malloc+strncpy) to do that.


You can do it for specific strings that you know in advance, presented to the macro as symbols rather than as string literals, but not for general symbols and not for string literals at all. For example:

#include <stdio.h>

#define STRINGIFY(s) # s
#define EXPAND_TO_STRING(x) STRINGIFY(x)
#define TRUNCATE_ObjectT Object
#define TRUNCATE_MrT Pity da fool
#define TRUNCATE(s) EXPAND_TO_STRING(TRUNCATE_ ## s)

int main(){
   printf(TRUNCATE(ObjectT)); // prints "Object"
   printf(TRUNCATE(MrT));     // prints "Pity da fool"
}

That relies on the token-pasting operator, ##, to construct the name of a macro that expands to the truncated text (or, really, the replacement text), and the stringification operator, #, to convert the expanded result to a string literal. There's a little bit of required macro indirection in there, too, to ensure that all the needed expansions are performed.