FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TTF_SizeText takes a char* instead of an immutable char*

 
Post new topic   Reply to topic     Forum Index -> Derelict
View previous topic :: View next topic  
Author Message
RobotGymnast



Joined: 06 Jan 2011
Posts: 23

PostPosted: Wed Jan 19, 2011 6:29 pm    Post subject: TTF_SizeText takes a char* instead of an immutable char* Reply with quote

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
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Sat Jan 22, 2011 7:41 am    Post subject: Reply with quote

C doesn't have name mangling so it shouldn't matter if it's const or not.
Back to top
View user's profile Send private message
RobotGymnast



Joined: 06 Jan 2011
Posts: 23

PostPosted: Sat Jan 22, 2011 9:17 am    Post subject: Reply with quote

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
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Sat Jan 22, 2011 9:35 am    Post subject: Reply with quote

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
View user's profile Send private message
RobotGymnast



Joined: 06 Jan 2011
Posts: 23

PostPosted: Sat Jan 22, 2011 9:36 am    Post subject: Reply with quote

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
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Sat Jan 22, 2011 9:39 am    Post subject: Reply with quote

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
View user's profile Send private message
RobotGymnast



Joined: 06 Jan 2011
Posts: 23

PostPosted: Sat Jan 22, 2011 9:41 am    Post subject: Reply with quote

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
View user's profile Send private message
Stanley Pancakes



Joined: 26 Dec 2009
Posts: 18

PostPosted: Mon Jan 24, 2011 4:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sun Apr 17, 2011 4:18 am    Post subject: Reply with quote

FYI, this is fixed in SVN.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Derelict All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group