Compiler nanny, take 2.

I found a better way than to use a function which I described earlier. The drawback of the function was that in some cases it requred the function to exist even in retail bits. So, now I do

static volatile bool s_fFalse = false;

#define ASSERT(x) do { if(x) { ... } } while(g_fFalse)

Volatile is the key. It makes compiler think that variable may change even if it is declared static and there is no code in sight that might be changing variable value. I guess compiler behaves correctly since there may be a tricky inline assembly somewhere or setjmp/longjmp (do you still remember what those puppies do?) or it is a memory-mapped port or something  🙂

You do pay the price of one bool declared in each source file.

Comments (2)

  1. Raymond Chen says:

    If you mark it __declspec(selectany) and give it external linkage, then there will be only one.

  2. Mikhail Arkhipov (MSFT) says:

    Good point!

Skip to main content