seeing-things / zwo

ZWO SDK and custom software for debugging and using it.
23 stars 4 forks source link

Packed field reference compiler error #82

Closed bgottula closed 1 year ago

bgottula commented 1 year ago

While working on upgrading nix to Mint 21.1 (based on Ubuntu Jammy) I got the following compiler error for capture:

[ 12%] Building CXX object src/CMakeFiles/capture.dir/SERFile.cpp.o
/home/rgottula/dev/zwo/capture/src/SERFile.cpp: In destructor ‘SERFile::~SERFile()’:
/home/rgottula/dev/zwo/capture/src/SERFile.cpp:119:26: error: cannot bind packed field ‘((SERFile*)this)->SERFile::header_->SERHeader_t::FrameCount’ to ‘int&’
  119 |                 header_->FrameCount,
      |                 ~~~~~~~~~^~~~~~~~~~
make[2]: *** [src/CMakeFiles/capture.dir/build.make:160: src/CMakeFiles/capture.dir/SERFile.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:98: src/CMakeFiles/capture.dir/all] Error 2

Some discussion of this:

Seems like gcc got stricter about some edge case for references to packed struct members. I don't fully understand the details, or exactly how to fix / work-around it.

@jgottula any suggestions?

jgottula commented 1 year ago

Having a look.

jgottula commented 1 year ago

The obvious real problem here is that the SER format was designed by an idiot

One possible workaround that might work, maybe: using #pragma pack instead of packed attribute https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36566#c11

jgottula commented 1 year ago

Another workaround would be to just declare an int32_t in that block scope, assign it the value of header_->FrameCount and then pass that in to the logging function.

Or just declare some inline by-value getters in struct SERHeader_t and use those; e.g.:

int32_t GetFrameCount() { return FrameCount; }
int32_t GetFrameCount() const { return FrameCount; }
jgottula commented 1 year ago

(And actually you’d only need the const-qualified getter. I put a const and non-const getter because I forgot what I was doing for a bit.)