Re: const char *

Fred Labrosse <[email protected]>
Newsgroups gmane.science.robotics.playerstage
Organization Aberystwyth University
Message-ID <[email protected]>
On Friday 6 August 2010 14:43:31 Rich Mattes wrote:
> It looks like the compiler is treating "crabbing" as a const-qualified
> string.  Since none of the set/get functions are expected to modify the
> key string you pass, it seems sane to modify all of them to accept
> const arguments (this guarantees that the function will just be looking
> at the value of the string, and won't modify it.)  You could go through
> and change all of the c/c++ client code to use const chars as
> arguments.  It would probably require a lot of work; in order to
> preserve the const qualifier in libplayerc you'd have to change the
> player_*prop_req_t structs (in libplayerinterface/player.h) so the
> property string is a const, then you'd have to change all the c and c++
> function prototypes and definitions, etc.

I started on that and then ended up at the stage of the player_*prop_req_t 
structs, at which point I stopped, waiting for some input from you guys.

> 
> As a workaround, you might also be able to do something like:
> 
> char* property = "crabbing";
> pp->SetIntProp(property,1);
> 
> This should get gcc off your back since you'd be passing a plain old
> char* like it wants.

Would probably work, but consts are nice in c++ and allow the compiler to 
optimise things so changing for consts where possible would be nice.

I'll look into it a bit more.

Fred

> 
> Rich
> 
> -----Original Message-----
> From: Fred Labrosse [mailto:[email protected]]
> Sent: Thursday, August 05, 2010 11:51 AM
> To: [email protected]
> Subject: [Playerstage-developers] const char *
> 
> All,
> 
> Whenever I call:
> 
> pp->SetIntProp("crabbing", 1);
> 
> my compiler complains:
> 
> warning: deprecated conversion from string constant to 'char*'
> 
> So I started editing clientproxy.h and clientproxy.cc in my svn working
> copy
> 
> to add the const's with a view of submitting a patch.
> 
> Obviously, the compilation fails because the underlying c code (in
> playerc.h)
> does not have the const's.  I haven't done any pure c in a while so I'm
> not too sure what to do with that.  I think gcc will be happy with
> added "const"s
> but this might not be generic enough.  And I'm not too sure what the
> repercussions of that will be with the rest of the code.  I could
> const_cast,
> but this somehow defeats the point...
> 
> Any suggestions?
> 
> Cheers,
> 
> Fred
> 
> ------------------------------------------------------------------------
> ---- --
> The Palm PDK Hot Apps Program offers developers who use the
> Plug-In Development Kit to bring their C/C++ apps to Palm for a share
> of $1 Million in cash or HP Products. Visit us here for more details:
> http://p.sf.net/sfu/dev2dev-palm
> _______________________________________________
> Playerstage-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/playerstage-developers
> 
> 
> ------------------------------------------------------------------------
> ------ This SF.net email is sponsored by
> 
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev
> _______________________________________________
> Playerstage-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/playerstage-developers

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.