FWGS / xash3d

DEPRECATED in favor of https://github.com/FWGS/xash3d-fwgs. Only bugfixes are accepted.
https://xash.su
GNU General Public License v3.0
549 stars 107 forks source link

Change some (char *) to (const char *) in eiface.h if possible #405

Closed MoeMod closed 5 years ago

MoeMod commented 5 years ago

In Modern C++, string literal is typed to (const char ), and it isn't allowed to convert to (char ). Since those interfaces are shared and referenced in both C and C++, it causes lots of warnings and sometimes requires const_cast<const char >. In my opinion, this change won't cause extra compatibility problems because (char ) can be converted to (const char *).

example:

std::string szModel("models/v_usp.mdl"); gEngfuncs.pfnPrecacheModel(szModel.c_str()); // cannot convert const char * to char *

possible solution:

typedef struct enginefuncs_s { int (*pfnPrecacheModel)( char* s ); to typedef struct enginefuncs_s { int (*pfnPrecacheModel)( const char* s );

a1batross commented 5 years ago

Hi. Yes, I am aware of that. Engine internally uses const where it's possible, so you can just add const modifier to interface and this will not break anything.

Don't remember though, did I or someone else already added constant modifiers to engine's eiface.h.

a1batross commented 5 years ago

Ah, it was already done in "hlsdk-xash3d".

https://github.com/FWGS/hlsdk-xash3d/blob/master/engine/eiface.h

MoeMod commented 5 years ago

Oh, I am sorry that I thought that the files in this repo is newer than those in that one. Maybe it need to be merged...

a1batross commented 5 years ago

I think, it would be better to move Xash3D/HLSDK headers to another repository, so we can sync changes between engine and different SDKs(XashXT, HLSDK and so on) and even track changes! :)