Home > Net >  Why do I get an error saying 'statement with no effect [-Werror=unused-value]'
Why do I get an error saying 'statement with no effect [-Werror=unused-value]'

Time:07-13

I am confused why I get an error on these 5 lines. I'd assume it would be just a warning but my compiler is taking all warnings as errors.

  161 |     kernelBuffer->BaseAddress;
      |     ~~~~~~~~~~~~^~~~~~~~~~~~~
src_uefi/main_uefi.c:162:17: error: statement with no effect [-Werror=unused-value]
  162 |     kernelBuffer->BufferSize;
      |     ~~~~~~~~~~~~^~~~~~~~~~~~
src_uefi/main_uefi.c:163:17: error: statement with no effect [-Werror=unused-value]
  163 |     kernelBuffer->Width;
      |     ~~~~~~~~~~~~^~~~~~~
src_uefi/main_uefi.c:164:17: error: statement with no effect [-Werror=unused-value]
  164 |     kernelBuffer->Height;
      |     ~~~~~~~~~~~~^~~~~~~~
src_uefi/main_uefi.c:165:17: error: statement with no effect [-Werror=unused-value]
  165 |     kernelBuffer->PixelsPerScanLine;

This is the file where the errors are happening 'main_uefi.c' https://pastebin.com/B5iTTzP5

Any idea why this could be happening and what I need to do to understand why this happens?

CodePudding user response:

You are not performing an operation in those lines. Instead of a field of a struct pointer such as kernelBuffer->BaseAddress;, imagine you had a primitive value, like int x;. Hopefully you can see why a line like x; does nothing. There's no assignment or any other operation: nothing for the program to actually do. If you removed those lines, none of the coded functionality would change one bit, which is what the warning is telling you.

  •  Tags:  
  • c
  • Related