vendredi 23 juillet 2021

How to properly check for a stack overflow/underflow on a primitive type in c++?

Problem

Currently I'm working on porting a cross-platform project that was originally written for 32 bit enviroments to work in 64. Trouble is that there are many areas where types like size_t and the SOCKET type in windows changed from 32 bit values to 64 bit values in the port and all throughout the code base there are conversions between these now 64-bit types and 32-bit types such as Poco::(U)Int32, and the 32 bit types can't be changed because the code base also makes use of some very low level bitwise math and memory management so just switching to Poco::(U)Int64 would require all of those values to be recalculated.

Question

What I'm trying to do is find a way that I can do something like overload the = operator so that I can check if the compiler warnings about truncation are actually occuring and the value is becoming malformed or if it's just the compiler being picky about not wanting to down cast the values even though it would fit in a 32 bit space.

Attempted Solutions

I tried creating a class wrapper around primitive types see here, that didn't work, but I haven't found any other ways around this issue.

Aucun commentaire:

Enregistrer un commentaire