October 22, 2024
Chicago 12, Melborne City, USA
C#

compiler complains that an unused variable is used when simply a cast to void is performed


We just found out that a certain compiler (Greenhills) sees the following construct as an error:

// local variable
mytype x;
...
((void) (x));

The compiler reports:
error #549-D: variable "x" is used before its value is set.

We’re using such constructs in special situations to avoid compiler warnings related to variables not being used at all. We want to test if the type really exists so this is totally intended.

My question is however related to how this compiler behaves. According to what C standard rule does the compiler decide that a cast to void (which should literally translate to nothing in assembler code) is actually "using" the variable?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video