Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
CompileTimeFlagChecker.h File Reference
#include "Stroika/Foundation/StroikaPreComp.h"
#include <cstdint>
#include "CompileTimeFlagChecker.inl"

Go to the source code of this file.

Namespaces

namespace  Stroika::Foundation
 

Macros

#define CompileTimeFlagChecker_HEADER(NS_PREFIX, NAME, VALUE)    CompileTimeCheck_HEADER_INTERNAL_ (NS_PREFIX, CompileTimeChecker_##NAME, CompileTimeCheck_##NAME, VALUE)
 CompileTimeFlagChecker_HEADER () will generate a LINK ERROR if you ever compile a header with one value and the corresponding CompileTimeFlagChecker_SOURCE () with another value.
 
#define CompileTimeFlagChecker_SOURCE(NS_PREFIX, NAME, VALUE)   CompileTimeCheck_SOURCE_PRIVATE_1_ (NS_PREFIX, CompileTimeCheck_##NAME, VALUE)
 

Detailed Description

Note
Code-Status: Beta
@todo   This is still a pretty weak implementation, so could use some revisiting. But better now
        as of Stroika v2.1d18

@todo   Make sure not actually generating code in release builds, but still generating enough code so
        we get linker erorr missing qStroika_Foundation_Debug_AssertionsChecked=1/0.

Definition in file CompileTimeFlagChecker.h.

Macro Definition Documentation

◆ CompileTimeFlagChecker_HEADER

#define CompileTimeFlagChecker_HEADER (   NS_PREFIX,
  NAME,
  VALUE 
)     CompileTimeCheck_HEADER_INTERNAL_ (NS_PREFIX, CompileTimeChecker_##NAME, CompileTimeCheck_##NAME, VALUE)

CompileTimeFlagChecker_HEADER () will generate a LINK ERROR if you ever compile a header with one value and the corresponding CompileTimeFlagChecker_SOURCE () with another value.

It is HOPED the linker will optimize these references out (else wise - they should be small, not super significant).

But still hopefully check them so that compiling with mixed CPP defines (-D defines) will cause an easily diagnosic error message.

If this check fails, you will see a linker message like

unresolved external symbol "unsigned char Stroika::Foundation::Debug::CompileTimeCheck_VARIABLENAME_BADVALUE
Example Usage
error LNK2001: unresolved external symbol "unsigned char Stroika::Foundation::Debug::CompileTimeCheck_qTraceToFile_0
means that the variable qTraceToFile was defined '0' in some header, but some other value (that would be 1) in the cpp file where Stroika was built.
Note
The CompileTimeFlagChecker_HEADER () must occur in the global namespace (in order to forward declare the shared variable in a specific namespace given by the first macro argument).
Example Usage
CompileTimeFlagChecker_HEADER (Stroika::Foundation::Debug, qTraceToFile, qTraceToFile);
#define CompileTimeFlagChecker_HEADER(NS_PREFIX, NAME, VALUE)
CompileTimeFlagChecker_HEADER () will generate a LINK ERROR if you ever compile a header with one val...
Note
DEFECT The VALUE (third) argument to CompileTimeFlagChecker_HEADER and CompileTimeFlagChecker_SOURCE must expand to zero or one, not a complex expression due to how the name macro name pasting works. UNDESIRABLE!.

Definition at line 61 of file CompileTimeFlagChecker.h.

◆ CompileTimeFlagChecker_SOURCE

#define CompileTimeFlagChecker_SOURCE (   NS_PREFIX,
  NAME,
  VALUE 
)    CompileTimeCheck_SOURCE_PRIVATE_1_ (NS_PREFIX, CompileTimeCheck_##NAME, VALUE)
Note
NS_PREFIX must be the namespace in which the CompileTimeFlagChecker_HEADER was declared.

Put exactly one of these in a single .cpp file that should be the definition of what everything else must be consistent with. It should take the same arguments as the corresponding CompileTimeFlagChecker_SOURCE ().

Example Usage
CompileTimeFlagChecker_SOURCE (Stroika::Foundation::Debug, qTraceToFile, qTraceToFile);
#define CompileTimeFlagChecker_SOURCE(NS_PREFIX, NAME, VALUE)
Note
DEFECT The VALUE (third) argument to CompileTimeFlagChecker_HEADER and CompileTimeFlagChecker_SOURCE must expand to zero or one, not a complex expression due to how the name macro name pasting works. UNDESIRABLE!.

Definition at line 93 of file CompileTimeFlagChecker.h.