While porting some crypto code from GCC to MSVC, I run into the old problem of MSVC not supporting the __int128 data type.
So, I decided to write a lightweight drop-in replacement class for the 128-bit integer datatype in MSVC, in order to avoid altering the original GCC crypto code as much as possible (it is big!).
I have overloaded/implemented all of the arithmetic operators (division and modulo were a bitch) and all other operators, which are being used by the original GCC code, except for the unary "address of" operator (&), because this article stated: "The unary address-of operator should never be overloaded."
Also, I have a problem with the sizeof() keyword because the original GCC code often uses sizeof() on __int128 sized variables.
What are the good coding practices to write such user-defined datatype in MSVC C++ ?
Why the "address of" operator should never be overloaded?
How should I write my __int128 class so I can rely on sizeof(MyInt128)==16
when MyInt128 is of the __int128 type, implemented by my drop-in replacement class ?
Is avoiding virtual functions and the presence of VFTP, enough? What about padding and the memory alignment of the 128-bit integer storage?
What are the other gotchas lurking out there when trying to implement my own drop-in __int128 user defined data type? ...casts?
P.S. Bigint libraries (GMP, Boost, etc..) all do it differently.