View previous topic :: View next topic |
Author |
Message |
RobotGymnast
Joined: 06 Jan 2011 Posts: 23
|
Posted: Wed Jan 19, 2011 6:29 pm Post subject: TTF_SizeText takes a char* instead of an immutable char* |
|
|
TTF_SizeText takes a const char* in the actual SDL TTF headers. However, the Derelict version seems to take a char* (according to my compiler), which is causing some consternation. Is not not supposed to be an immutable char*, like TTF_RenderText et al? |
|
Back to top |
|
|
doob
Joined: 06 Jan 2007 Posts: 367
|
Posted: Sat Jan 22, 2011 7:41 am Post subject: |
|
|
C doesn't have name mangling so it shouldn't matter if it's const or not. |
|
Back to top |
|
|
RobotGymnast
Joined: 06 Jan 2011 Posts: 23
|
Posted: Sat Jan 22, 2011 9:17 am Post subject: |
|
|
It does matter. When I try to pass an immutable char* to TTF_SizeText, it gives me a compile-time error because it takes a char*. |
|
Back to top |
|
|
doob
Joined: 06 Jan 2007 Posts: 367
|
Posted: Sat Jan 22, 2011 9:35 am Post subject: |
|
|
What I meant was if the C function is declared as "void foo (const char*);" and in D you can declare it as "void foo (char*)" , "void foo (const char*)" or something else it will still call the same C function. |
|
Back to top |
|
|
RobotGymnast
Joined: 06 Jan 2011 Posts: 23
|
Posted: Sat Jan 22, 2011 9:36 am Post subject: |
|
|
Ah. It's just that the D compiler complains when trying to pass an immutable char*, so I have to explicitly cast away the immutable and hope that it won't mess anything up. |
|
Back to top |
|
|
doob
Joined: 06 Jan 2007 Posts: 367
|
Posted: Sat Jan 22, 2011 9:39 am Post subject: |
|
|
If you have an array or a string you can call .dup to get a mutable copy and then call .ptr to get the pointer. |
|
Back to top |
|
|
RobotGymnast
Joined: 06 Jan 2011 Posts: 23
|
Posted: Sat Jan 22, 2011 9:41 am Post subject: |
|
|
True, but isn't this a linear-time process? And a .dup of a string isn't null-terminated, is it? The whole reason I'm having this problem is that toStringz returns an immutable char* |
|
Back to top |
|
|
Stanley Pancakes
Joined: 26 Dec 2009 Posts: 18
|
Posted: Mon Jan 24, 2011 4:02 pm Post subject: |
|
|
I doubt it's linear-time, but for the null-termination you are right.
You may edit your local Derelict sources to make TTF_SizeText take 'in char*' instead of 'char*'. It may even help to submit a patch for it: anyway, most prototypes in Derelict use 'in' keyword (see for example SDL_LoadWAV) to replace const. |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
|
Back to top |
|
|
|