Topic: C++ Standards Bug!!!
Author: Ray Brown <102336.141@CompuServe.COM>
Date: 1995/08/19 Raw View
Distribution:
The challenge: try to rewrite the last two lines of this code
without a typedef (typedefs should never be required, right?).
//////////////////////////////////////////////////////////////
struct B
{
void Foo(short);
};
struct A
{
static void (B::* var)(short);
};
typedef void (B::*q)(short);
q A::var = B::Foo;
//////////////////////////////////////////////////////////////
--
#################################################################
Email: Ray.Brown@lawson.com
Phone: (612) 379-8086 x4393
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/08/19 Raw View
Distribution:
Ray Brown <102336.141@CompuServe.COM> writes:
>The challenge: try to rewrite the last two lines of this code
>without a typedef (typedefs should never be required, right?).
>//////////////////////////////////////////////////////////////
>struct B
>{
> void Foo(short);
>};
>struct A
>{
> static void (B::* var)(short);
>};
>typedef void (B::*q)(short);
>q A::var = B::Foo;
>//////////////////////////////////////////////////////////////
You can write it without a typedef like this:
void (B::* A::var)(short) = B::Foo;
--
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: Ray Brown <102336.141@CompuServe.COM>
Date: 1995/08/20 Raw View
Distribution:
>You can write it without a typedef like this:
>void (B::* A::var)(short) = B::Foo;
All right, so this turned out to be a compiler question to some
extent. The solution you gave does not work under gcc version
2.5.6: the error message is "multiple `::' terms in declarator
invalid." It does work with some other compilers.
However, consider this: let the declaration of var be
static void (B::*const var)(short);
within struct A. How do you perform the initialization now? Oddly
enough, your answer still works with some compilers, even though
these very compilers usually require that the full type of the
variable to be initialized (var) be given at initialization time.
I have not found a way to express the type (with "const") without
a typedef at initialization time and I can't explain why it would
not be required to do so.
Any ideas? Standards bug after all or common compiler bug?
--
#################################################################
Email: Ray.Brown@lawson.com
Phone: (612) 379-8086 x4393
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/08/21 Raw View
Ray Brown <102336.141@CompuServe.COM> writes:
>Distribution:
>>You can write it without a typedef like this:
>>void (B::* A::var)(short) = B::Foo;
>All right, so this turned out to be a compiler question to some
>extent. The solution you gave does not work under gcc version
>2.5.6: the error message is "multiple `::' terms in declarator
>invalid." It does work with some other compilers.
>However, consider this: let the declaration of var be
> static void (B::*const var)(short);
>within struct A. How do you perform the initialization now? ...
>Any ideas? Standards bug after all or common compiler bug?
I still don't see the problem. If 'var' is const, you initialize it
void (B::* const A::var)(short) = B::Foo;
There aren't any special rules at work here, but according to your
report, some compilers have trouble with the syntax. For almost
every feature of every language, some compiler somewhere has a
bug. That doesn't in itself mean the standard has a bug.
The syntax for pointer-to-member is horribly ugly -- I think on
purpose :-) -- and is not widely used. Consequently, it takes a
while for all the bugs to disappear from all compilers.
Finally, why are you allergic to typedefs? I prefer to use typedefs,
particularly for function pointers since the syntax is too hard
to read.
---
Steve Clamage, stephen.clamage@eng.sun.com
--
Steve Clamage, stephen.clamage@eng.sun.com
Author: jason@cygnus.com (Jason Merrill)
Date: 1995/08/21 Raw View
>>>>> Ray Brown <102336.141@CompuServe.COM> writes:
>> You can write it without a typedef like this:
>> void (B::* A::var)(short) = B::Foo;
> All right, so this turned out to be a compiler question to some
> extent. The solution you gave does not work under gcc version
> 2.5.6: the error message is "multiple `::' terms in declarator
> invalid." It does work with some other compilers.
Including later versions of gcc, I might add.
Jason
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: ebiederm@cse.unl.edu (Eric Biederman)
Date: 1995/08/22 Raw View
Distribution:
In article <418s1k$7oc@engnews2.Eng.Sun.COM> clamage@Eng.Sun.COM (Steve Clamage) writes:
Finally, why are you allergic to typedefs? I prefer to use typedefs,
particularly for function pointers since the syntax is too hard
to read.
Just at note, there are some cases involving templates especially
template arguments that are next to impossible to write with a cast.
consider:
template <class A,class B,void (*c)(A&, B&)>
class Z { ... };
It's the best I can think of off the top of my head.
Now does the standard allow, any way to use a typedef here?
Eric
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]