Qt macro keywords cause name collisions

You can define the QT_NO_KEYWORDS macro, that disables the “signals” and “slots” macros. If you use QMake: CONFIG += no_keywords (Qt Documentation here) If you’re using another build system, do whatever it needs to pass -DQT_NO_KEYWORDS to the compiler. Defining QT_NO_KEYWORDS will require you to change occurrences of signals to Q_SIGNALS and slots to Q_SLOTS … Read more

Should variable definition be in header files?

One thing that I’ve used in the past (when global variables were in vogue): var.h file: … #ifdef DEFINE_GLOBALS #define EXTERN #else #define EXTERN extern #endif EXTERN int global1; EXTERN int global2; … Then in one .c file (usually the one containing main()): #define DEFINE_GLOBALS #include “var.h” The rest of the source files just include … Read more

What does ## in a #define mean?

A little bit confused still. What will the result be without ##? Usually you won’t notice any difference. But there is a difference. Suppose that Something is of type: struct X { int x; }; X Something; And look at: int X::*p = &X::x; ANALYZE(x, flag) ANALYZE(*p, flag) Without token concatenation operator ##, it expands … Read more

What is the NDEBUG preprocessor macro used for (on different platforms)?

The only ‘standard’ thing about NDEBUG is that it’s used to control whether the assert macro will expand into something that performs a check or not. MSVC helpfully defines this macro in release build configurations by defining it in the project for you. You can change that manually by editing the project configuration. Other toolchains … Read more

C++ #include semantics

After reading all answers, as well as compiler documentation, I decided I would follow the following standard. For all files, be them project headers or external headers, always use the pattern: #include <namespace/header.hpp> The namespace being at least one directory deep, to avoid collision. Of course, this means that the project directory where the project … Read more

Solution-wide #define

Update: You cannot do a “solution-wide” define afaik, however the answer below is workable on a per-project basis. You set them in your Compilation Properties or Build options: http://msdn.microsoft.com/en-US/library/76zdzba1(v=VS.80).aspx (VS2008) http://msdn.microsoft.com/en-US/library/76zdzba1(v=VS.100).aspx (VS2010) see the “To set a custom constant” heading. Update Microsoft Documentation on Build Options You get to the build options by right-clicking the … Read more