stevemk14ebr / PolyHook_2_0

C++20, x86/x64 Hooking Libary v2.0
MIT License
1.58k stars 222 forks source link

Fix compile warning in x86 #181

Closed BullyWiiPlaza closed 1 year ago

BullyWiiPlaza commented 1 year ago

When compiling my x86 hooking code, I was getting the following warning in MSVC:

1>C:\vcpkg\installed\x86-windows\include\polyhook2\Instruction.hpp(198,3): warning C4018: '<=': signed/unsigned mismatch

stevemk14ebr commented 1 year ago

No C++ style casts please, change to C style and I'll merge.

BullyWiiPlaza commented 1 year ago

Okay but what's your reasoning behind it? Using C style casts in C++ are considered bad style. I now updated the pull request and used a C style cast instead.

stevemk14ebr commented 1 year ago

A C style cast is the same as trying all C++ casts in order excluding a dynamic_cast. It's easier to read, more powerful, and shorter to write. For low level code like this where 'unsafe' stuff happens everywhere following the normal C++ rules does not make sense.

I prefer to write C++ as a superset of C, meaning do it like C when possible, but if not possible then use C++ features. This results in simpler code.