Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to replace part of word with the preprocessor?

Tags:

c

objective-c

I have something like this in my objective-C class

@interface PREFIX_MyClass {
...
@end

and I'd like to use the preprocessor to convert it to:

@interface AwesomeMyClass {
...
@end

so something like

#define PREFIX_ Awesome

doesn't work because it's a part of a word. Any other way? I know I can use something like this:

#define PrefixClass(NAME) Awesome##NAME

@interface PrefixClass(MyClass)

but I don't like this because it breaks code complete and reference following in dev tools (i.e.: Xcode in this case)

like image 978
pho0 Avatar asked Nov 05 '22 00:11

pho0


1 Answers

This isn't very elegant, but you could use the preprocessor to replace the entire class name instead of just part.

#define PREFIX_MyClass AwesomeMyClass
@interface PREFIX_MyClass

Of course, this becomes an issue if you use the prefix more than once and it changes. You could fix this using by using another calling another macro to add the prefix, so that only one macro contains the actual prefix.

#define ADD_PREFIX(name) Awesome##name
#define PREFIX_MyClass ADD_PREFIX(MyClass)
@interface PREFIX_MyClass

This still requires a macro for everything you want to prefix, but code completion will recognize the PREFIX_MyClass name.

like image 109
ughoavgfhw Avatar answered Nov 11 '22 14:11

ughoavgfhw