Question

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?

Was it helpful?

Solution

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)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top