On Wed, 17 Oct 2007, Holger Macht wrote: > On Wed 17. Oct - 17:53:53, Richard Guenther wrote: > > On Wed, 17 Oct 2007, Richard Guenther wrote: > > > > > On Wed, 17 Oct 2007, Holger Macht wrote: > > > > > > > On Wed 17. Oct - 13:09:30, Marcus Rueckert wrote: > > > > > On 2007-10-17 12:56:51 +0200, Holger Macht wrote: > > > > > > What would result in > > > > > > > > > > > > char *prop = (char*)"laptop_panel.num_levels"; > > > > > const char *prop = "laptop_panel.num_levels"; > > > > > > > > > > should fix it too no? > > > > > > > > Of course it does. > > > > > > > > I also have to change everything like: > > > > > > > > void testfunc(char *str); > > > > testfunc("foo"); > > > > to > > > > testfunc((char*)"foo"); > > > > > > No, the correct fix is to make testfunc take a const char *. > > > > So what about functions which modify their arguments and thus can't take a > const?
For those it would be even more wrong to pass a constant string literal, the function would simply segfault in that case. For those you need to use char tmp[] = "foo"; bar (tmp); which constructs a stack temporary string with the contents "foo" and thus allows writing into it. Richard. -- Richard Guenther <[EMAIL PROTECTED]> Novell / SUSE Labs SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]