Subject: Re: CVS commit: src/sys/sys
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: Christos Zoulas <christos@zoulas.com>
List: source-changes
Date: 12/11/2004 18:46:32
On Dec 12, 8:20am, yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi) wrote:
-- Subject: Re: CVS commit: src/sys/sys
| > The following does not work:
| >
| > const char *foo[2];
| > char **bar = (char **)__UNCONST(foo);
|
| it's intended not to work because foo and bar is not compatible.
| at least it's an intention when i wrote the gcc version of __UNCONST.
Yes they are compatible (at least for the part that they are both arrays
of strings). The issue that keeps coming up is the following:
const char *argv[] = { "foo", "-a", "b", NULL };
execvp(argv[0], argv);
How do you use your __UNCONST to fix it? Or how do you write this so
that gcc with -Wcast-qual works?
| > Also having 2 versions with slightly different semantics (they return
| > different types) just leads to confusion.
|
| do you mean, the semantics of __UNCONST should be
| "convert any type to void *"?
| it's horrible and it doesn't match with its name, IMO.
No, I am saying that not all compilers have __typeof__ so you cannot
portably write __UNCONST without passing it the type you want to cast
to. At this point, passing the type is pointless because it is cleaner
to use the cast when you need to. Finally having 2 versions of __UNCONST
that behave differently for __UNCONST(foo) + 1 is bogus.
christos