Re: [patch] const_cast to be replaced by str_unconst

2005-04-14 Thread Roland Illig
Oswald Buddenhagen wrote:
whoops, this is exactly what you're talking about. :}
anyway, i don't think this extra warning would matter, given that it
would be in the same location in every file.
and, fwiw, isn't it possible to use a #pragma or some __attribute__ to
get rid of the warning?
There's a fairly easy way to select between few warnings and the inlined 
function:

#define INLINE_STR_UNCONST
Just look at the current src/util.h
I have made non-inlining the default, for producing fewer warnings. For 
release (or non-developer) versions, we may #define INLINE_STR_UNCONST 
in  or in configure.ac, next to the -DNDEBUG.

Roland
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [patch] const_cast to be replaced by str_unconst

2005-04-14 Thread Oswald Buddenhagen
On Thu, Apr 14, 2005 at 07:19:28PM +0200, Oswald Buddenhagen wrote:
> On Tue, Apr 12, 2005 at 08:28:50PM +0200, Roland Illig wrote:
> > >You can inline it.
> > 
> > When compiling with gcc using -Wcast-qual, this would give us a warning 
> > for every file.
> >
> ???
> put
> static inline unconst***() { ... }
> in the header file and be fine.
> of course you need a configure check that optionally #defines inline to
> nothing.
> 
whoops, this is exactly what you're talking about. :}
anyway, i don't think this extra warning would matter, given that it
would be in the same location in every file.
and, fwiw, isn't it possible to use a #pragma or some __attribute__ to
get rid of the warning?

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [patch] const_cast to be replaced by str_unconst

2005-04-14 Thread Oswald Buddenhagen
On Tue, Apr 12, 2005 at 08:28:50PM +0200, Roland Illig wrote:
> Pavel Tsekov wrote:
> >>For those of you that are concerned about the performance loss of an
> >>extra function call: It is much more important for the code to be
> >>readable and checkable by the compiler than to be 1 millisecond faster
> >>at all.
> >
> >You can inline it.
> 
> When compiling with gcc using -Wcast-qual, this would give us a warning 
> for every file.
>
???
put
static inline unconst***() { ... }
in the header file and be fine.
of course you need a configure check that optionally #defines inline to
nothing.

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [patch] const_cast to be replaced by str_unconst

2005-04-13 Thread Roland Illig
I have just committed str_unconst().
I will slowly replace the uses of const_cast by str_unconst().
Roland
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [patch] const_cast to be replaced by str_unconst

2005-04-12 Thread Oskar Liljeblad
On Tuesday, April 12, 2005 at 20:16, Roland Illig wrote:
> >>   char *str_unconst(const char *);
[..]
> >In what way is this function (or macro) useful? It seems to break the
> >whole point with 'const' in C. If something is const, you shouldn't
> >touch it. Or should you?
> 
> We are using SLang and Samba, which both don't know about the "const" 
> qualifier. The function is meant for exactly these cases, which I hope 
> will disappear in the next future. But that's only a dream. :)
> 
> in vfs/samba/include/smb.h, line 72, you can find:
> 
> int Debug1 (char *, ...);
> 
> in slang/include/slang.h, line 155:
> 
> extern char *SLmemcpy (char *, char *, int);

Ah I see. I've come across that problem in other libraries as well
(libupnp for another application). If it only was easy to fix the
source of the problem (the function prototypes in those libraries!),
but unfortunately it isn't always...

Regards,

Oskar Liljeblad ([EMAIL PROTECTED])
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [patch] const_cast to be replaced by str_unconst

2005-04-12 Thread Roland Illig
Oskar Liljeblad wrote:
On Tuesday, April 12, 2005 at 12:27, Roland Illig wrote:
I'd like to introduce a new function:
   char *str_unconst(const char *);
The function returns a string that compares equal to its argument, but 
does not have the "const" qualifier. Currently it just returns its 
argument, cast to (char *).
In what way is this function (or macro) useful? It seems to break the
whole point with 'const' in C. If something is const, you shouldn't
touch it. Or should you?
We are using SLang and Samba, which both don't know about the "const" 
qualifier. The function is meant for exactly these cases, which I hope 
will disappear in the next future. But that's only a dream. :)

in vfs/samba/include/smb.h, line 72, you can find:
int Debug1 (char *, ...);
in slang/include/slang.h, line 155:
extern char *SLmemcpy (char *, char *, int);
Roland
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [patch] const_cast to be replaced by str_unconst

2005-04-12 Thread Roland Illig
Pavel Tsekov wrote:
For those of you that are concerned about the performance loss of an
extra function call: It is much more important for the code to be
readable and checkable by the compiler than to be 1 millisecond faster
at all.
You can inline it.
When compiling with gcc using -Wcast-qual, this would give us a warning 
for every file. The non-inlined version would produce the warning only 
for one file, namely src/util.c.

I want as few warnings as possible.
Roland
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [patch] const_cast to be replaced by str_unconst

2005-04-12 Thread Oskar Liljeblad
On Tuesday, April 12, 2005 at 12:27, Roland Illig wrote:

Hi!

> I'd like to introduce a new function:
> 
> char *str_unconst(const char *);
> 
> The function returns a string that compares equal to its argument, but 
> does not have the "const" qualifier. Currently it just returns its 
> argument, cast to (char *).

In what way is this function (or macro) useful? It seems to break the
whole point with 'const' in C. If something is const, you shouldn't
touch it. Or should you?

Regards,

Oskar Liljeblad ([EMAIL PROTECTED])
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [patch] const_cast to be replaced by str_unconst

2005-04-12 Thread Pavel Tsekov
Hello,

On Tue, 12 Apr 2005, Roland Illig wrote:

> I like this version much more than the const_cast macro I introduced
> some months ago. Compare these:

I mean no offense,  but please save us all the "I like this", "I
like that". It's obvious that you check in what you like.

> For those of you that are concerned about the performance loss of an
> extra function call: It is much more important for the code to be
> readable and checkable by the compiler than to be 1 millisecond faster
> at all.

You can inline it.
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel