> > +#define DEBUG(Expression)                                \
> > +    do {                                                   \
> > +      _Pragma("GCC diagnostic push")                       \
> > +      _Pragma("GCC diagnostic ignored \"-Wunused-value\"") \
> > +      if ((FALSE)) {                                       \
> > +        (VOID) Expression;                                 \
>
> So what is the point of the VOID cast here? Usually, these are added
> to avoid unused value warnings, but these are disabled explicitly via
> the pragma.

```
$ cat test.c
static int a = 0;

void foo()
{
  if ((0)) {
    (void)((void *)(long)0, a);
  }
}
$ clang -c -Wall test.c -o test.o
test.c:6:12: warning: expression result unused; should this cast be to
'void'? [-Wunused-value]
    (void)((void *)(long)0, a);
           ^     ~
1 warning generated.
```

Without the pragmas, various DEBUG statements sent into the macro
generate unused *value* warnings exactly such as the above. Once we
suppress these unused value warnings, the existence of the
comma-operator separated list of values, cast to void, avoids unused
*variable* warnings, such as the unused variable warning that would
otherwise occur about `a` above - allowing `a` to instead just be
optimised away when it becomes unused in this way, as we want.

For the other questions, let me get back to you! Thank you.


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


Reply via email to