Search code examples
c++sdl-2sdl-ttf

Why does TTF_RenderText_Blended need a const char?


I am trying to use the result of a function to feed a string to TTF_RenderText_Blended. this would mean it needs to be a variable,however. looking at the declaration it insists that the argument must be a const char.


Solution

  • I assume you mean const char *, i.e. a pointer to a constant string (that's what the reference manual says), meaning the function can not modify the string. Which is precisely the meaning of using const here, to tell the compiler (and the user of the API) that the function will not modify the string. This allows you to pass a string literal safely to the function, for other strings just pass it normally and it will work just the same.