mas-bandwidth/netcode

Clang and ISO C++11 compatibility

Closed this issue · 8 comments

Hello! First and foremost, thanks for your work on this. I've been trying to improve my C/C++ and network programming skills and netcode.io makes for an excellent project to learn from. That being said, I've been using clang++4.0 [-std=c++11 -Werror] on Linux as my primary dev environment and when I include netcode.h and attempt to initialize it, a series of errors like the following emerge:

ISO C++11 does not allow conversion from string literal to 'char *'

My fix was just to change 'char *' to 'const char *' on arguments and return values (among others) that were causing problems. Does this feel like an appropriate way to handle this issue?

Thanks again. netcode.io rocks.

I'm not 100% sure I can do this as-is, since old style C won't allow const. Is there some #ifdef way we can use the const char* only if it is C++ instead?

Ah, OK. I wasn't aware const was a problem with old style C. I'll look into another solution and get back to you!

I think if we can find an #ifdef that tests if C89 or greater, or C++, then we can use const, then this will solve both problems. const was introduced to C in C89.

To be clear, I'm very happy for you to solve this, you just have to work out how to maintain compatibility with old style C as well.

Hey! Sorry, I've been wrapped up in other things and haven't had a chance to work on this. Two questions for you if you have a moment. First, in removing my "const"s I saw that a few others remained. Specifically the netcode assert and printf functions. Should these be removed as well? Lastly, do you have a recommendation for validating that the fix complies with pre-c89 specifications? I didn't see any obvious compiler flags but admit this is new territory for me. Thanks.

Yes, there are similar C++11 complaints re. const char* literals that I worked around, that should be fixed in the same way. I can dig in and see if there is some way to detect this, otherwise it could be "NETCODE_HAS_CONST 1" up to the user or something like this. cheers

Should be resolved in e6dbc8b

You beat me to it! hat tip