nathhB / nbnet

single header C(99) library to implement client-server network code for games
zlib License
434 stars 26 forks source link

Fix for MSVC C++ Compilation Issue with Compound Literals #36

Closed AlanParadis closed 1 year ago

AlanParadis commented 1 year ago

This pull request addresses compilation issues encountered when using MSVC as a C++ compiler with the library. While I understand that this library is primarily designed to be a C99 library, there's an example provided that integrates with raylib. Given that raylib can be compiled in C++, it would be beneficial for this library to be compatible with C++ compilation as well.

The original code utilized compound literals, a feature introduced in C99. While this is valid in C99, MSVC does not support this feature when compiling in C++ mode, leading to two errors:

To address these issues, I've introduced a temporary variable to initialize the struct before passing it to the function. This change ensures compatibility with MSVC and allows for successful compilation in C++.

I believe this adjustment will enhance the library's versatility, especially for those who might be using MSVC as their C++ compiler or integrating with C++ projects. Feedback and suggestions are welcome!

nathhB commented 1 year ago

Approved. I merged your branch in the github-actions branch where I'm currently working on a CI for the library and the tests that were supposed to pass passed, so I'm going to merge it. Thanks again for this contribution, I really appreciate it.