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


[patch] const_cast to be replaced by str_unconst

2005-04-12 Thread Roland Illig
Hi all,
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 *).

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

ms = const_cast(char *, cs);
ms = str_unconst(cs);
The latter is shorter, has fewer chances for typing errors and is not as 
powerful as the former. You could have passed an int (or any other 
value) before, and that had been converted (or promoted, or whatever 
that type cast means in that case) to a char *. That took an important 
possibility to check for bugs from the compiler.

There's also the naming issue. Apparently, Bjarne Stroustrup has not had 
enough letters to name the const_cast unconst_cast, which would be more 
appropriate. The current name is just misleading, so I want to abandon it.

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.

Roland
Index: src/util.h
===
RCS file: /cvsroot/mc/mc/src/util.h,v
retrieving revision 1.66
diff -u -p -r1.66 util.h
--- src/util.h  8 Feb 2005 10:46:01 -   1.66
+++ src/util.h  12 Apr 2005 10:33:49 -
@@ -3,6 +3,12 @@
 
 #include 
 
+/* Returns its argument as a "modifiable" string. This function is
+ * intended to pass strings to legacy libraries that don't know yet
+ * about the "const" modifier. The return value of this function
+ * MUST NOT be modified. */
+extern char *str_unconst (const char *);
+
 /* String managing functions */
 
 extern const char *cstrcasestr (const char *haystack, const char *needle);
Index: src/util.c
===
RCS file: /cvsroot/mc/mc/src/util.c,v
retrieving revision 1.125
diff -u -p -r1.125 util.c
--- src/util.c  23 Mar 2005 05:29:06 -  1.125
+++ src/util.c  12 Apr 2005 10:33:47 -
@@ -1441,3 +1441,9 @@ cstrcasestr (const char *haystack, const
 }
 return NULL;
 }
+
+extern char *
+str_unconst (const char *s)
+{
+   return (char *) s;
+}
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel