Jump to content
  • Advertisement
Sign in to follow this  
Genjix

casting help

This topic is 4803 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

thread1 = SDL_CreateThread(printer, "Alpha");

genjix@linux:~/media/programming/c++/game/sdl/thread> g++ main.cpp -lSDL
main.cpp: In function `int main(int, char**)':
main.cpp:98: error: invalid conversion from `const void*' to `void*'
main.cpp:99: error: invalid conversion from `const void*' to `void*'
? how should I cast int printer(void *data) to int (SDLCALL *fn)(void *)? Why is it const void*? And how should I use const_cast?

Share this post


Link to post
Share on other sites
Advertisement
my educated guess it that's it's actually the "Alpha" string that really doesn't want to be casted since it's const. Simple workaround

char Alpha[] = "Alpha";
thread1 = SDL_CreateThread(printer, Alpha);

Share this post


Link to post
Share on other sites
nice one ;) didn't notice that.

thread1 = SDL_CreateThread(printer, const_cast<char*>("Alpha"));


(weird, the compiler is default casting from char* to void* because the function definition accepts void*
extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data);)

Share this post


Link to post
Share on other sites
Just be sure to not write through that void* since that would send you straight to the land of undefined behaviour... and that's a *bad* thing.

String literals are const just so you know.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!