Changing char* to const char* in SDK?

Posted By: MasterQ32

Changing char* to const char* in SDK? - 10/05/14 15:56

Hey!

I'm currently working with the Engine SDK and i'm wondering why functions like bmap_create need to have a char* parameter?
It's really annoying as i also need to cast string literals to char*:
Code:
BMAP *bmp = bmap_create((char*)"filename.png");



Much better would be the "correct" version with const char* instead of char*.

I don't think those methods have any sideffects on the parameter, right? Would be nice if this could be expressed in the method call itself.

Regards
Felix
Posted By: Wjbender

Re: Changing char* to const char* in SDK? - 10/06/14 13:42

it is annoying to type cast so much with gs in c++
that is why I use macros and re written functions instead... wich is also a bummer
Posted By: jcl

Re: Changing char* to const char* in SDK? - 10/06/14 16:15

If you need type casts depends on your compiler version and project settings. But you can redefine the functions with const char* in afuncs.h - they have been defined with char* for using the same header both in C++ and lite-C.
Posted By: MasterQ32

Re: Changing char* to const char* in SDK? - 10/06/14 16:52

Maybe it could be done with a specific define for constness:
Code:
// acknex.h
#define ENGINE_CONST


Code:
// adll.h
#define ENGINE_CONST const


Code:
// afuncs.h
EXT BMAP* F(bmap_create)(ENGINE_CONST char* filename);



I adjusted the prototypes in my current afuncs.h but i'm don't think this should be done by any user...
Posted By: jcl

Re: Changing char* to const char* in SDK? - 10/06/14 16:54

Normally not, but you have my special permission. wink
© 2024 lite-C Forums