0

I have defined macros in my pre-compiled header file as well as in another header file named Constants.h.

Which is the better way, and why?

jscs
  • 63,694
  • 13
  • 151
  • 195
Samir
  • 902
  • 9
  • 23

2 Answers2

1

Personally I wouldn't recommend the precompiled headers approach for many reasons, check here:

http://qualitycoding.org/precompiled-headers/

Apple uses the precompiled headers for AppKit, UIKit, Foundation, CoreData,... because there are hundreds of *.h files that don't change at all in every compilation of you app. Your custom macros, however, take just a few bytes and the overhead is negligible (Unless you have hundreds or thousands of macros)

Merlevede
  • 8,140
  • 1
  • 24
  • 39
  • nice and informative(as per link you have shared), Its right that our code has more dependency over macros in .pch but its useful in checking conditions, passing parameters and we will have less bugs. But i completely agree that importing many system headers will be problematic. I would never like to add in .pch – Samir Feb 07 '14 at 11:41
0

The better way is .h file cause it will always be compiled. pch file is precompiled and can lead to problems when changes occurred but it didn't rebuild the pch part.

In addition to that it is just more convenient to have every global constant in an constant.h file and not distributed over many files.

lukaswelte
  • 2,951
  • 1
  • 23
  • 45