I wonder if macros only have pros in any programming language. As there must be the limit we can create macros, and in frequency of use.
Suppose we create 100 macros in a class and imported that in 100 class of an application project. Is this a right approach?
#defineis useful for:#includeC and C++ headers,#importObjC headers)UIKIT_EXTERN) which must be resolved during preprocessing.NS_AVAILABLE_IOS()) which must be resolved during preprocessing.for everything else, there is an alternative which will save you headaches along the way.
no – that is terrifying 🙂
Cons
There are many. Too often, the program will be difficult to understand by humans and programs (compiler, parser, indexer) alike. It’s a good way to introduce bugs, and completely replace text of unrelated programs (via a simple
#import). There are more modern replacements for pretty much everything (e.g. functions, inline, typedef, constants, enums) — Allow the compiler to make your life easier!