On 23/11/2021 06:41, Marvin Häuser wrote:
23.11.2021 00:17:30 Michael Brown <mc...@ipxe.org>:
I would very strongly recommend having the non-debug version of the macro use 
something like:

#define ASSERT(Expression) do {   \
      if (FALSE) {                  \
        (VOID) (Expression);        \
      }                             \
    } while (FALSE)

Without the "if (FALSE)", you will find that an expression that may have 
side-effects (e.g. by calling an external function) will result in executable code being 
generated.

In theory +1, but don't some compilers generate "unreachable code" warnings for 
this? I unfortunately cannot check them all right now. Maybe guards push/pop'ing the 
warning for that need to be defined, that are only allowed to be used with explicit 
documentation why they are necessary?

A quick experiment shows that gcc won't generate a warning but clang will. Can be fixed by adding extra parentheses around FALSE:

#define ASSERT(Expression) do {   \
    if ((FALSE)) {                \
      (VOID) (Expression);        \
    }                             \
  } while (FALSE)

which is still clean and relatively elegant.

Thanks,

Michael


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#83938): https://edk2.groups.io/g/devel/message/83938
Mute This Topic: https://groups.io/mt/87172427/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to