Skip to main content
1 of 3
wcminipgasker2023
  • 2.7k
  • 1
  • 14
  • 29

Is updating a macro value in Xcode preprocessors marcos violating open closed principle?

For example, for some xcode projects, if I have some places that defines a number at some .cpp files:

const int PAGE_MAX=5;

and a new requirement comes that needs to change PAGE_MAX, I need to modify the .cpp file, it is violating principle. What if I define PAGE_MAX with macros? eg:

const int PAGE_MAX=XCODE_MACRO_PAGE_MAX;

but XCODE_MACRO_PAGE_MAX is not defined in other headers ,.c,or .cpp files, instead I define it in the Xcode -> Preprocessor macro sessions :

XCODE_MACRO_PAGE_MAX=5

when I need to update the value, I open the project in xcode and go to "Preprocessor macro sessions" to change the value of XCODE_MACRO_PAGE_MAX in the UI, eg: from XCODE_MACRO_PAGE_MAX=5 to XCODE_MACRO_PAGE_MAX=6.

While I don't need to edit the .cpp, the macro replaces XCODE_MACRO_PAGE_MAX with the new value, which feels the effect as if changing the .cpp actually when changing the macro value, is it violating open closed principle?

wcminipgasker2023
  • 2.7k
  • 1
  • 14
  • 29