freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [pooma-dev] enums vs. static data members


From: Julian C. Cummings
Subject: RE: [pooma-dev] enums vs. static data members
Date: Mon, 26 Mar 2001 12:39:10 -0800

OK, thanks for your input on this subject.
I didn't realize it was all right to initialize
static const data members inside the class
definition as Jim showed.  That's handy!

I am not completely sure that changing these enums
to static const bools will solve all of aCC's
problems, but I will take a crack at it and see.
If nothing else, it will simplify the Domain code,
which is far too complicated already.

-- Julian C.


Dr. Julian C. Cummings
Staff Scientist, CACR/Caltech
(626) 395-2543
address@hidden


-----Original Message-----
From: address@hidden [mailto:address@hidden
Sent: Friday, March 23, 2001 12:43 PM
To: address@hidden
Subject: [pooma-dev] enums vs. static data members


Hi All,

This is mostly directed at the Mac/Metrowerks folks,
but anyone is welcome to comment.  A couple of months
ago, I was trying to get Pooma 2.3 to build under the
HP aCC C++ compiler.  This is of interest here because
the HP V-class machine and the new "Superdome"
machine are major parallel platforms for us.  The aCC
compiler has a flag "-AA" which makes it quite ANSI
standard compliant.  It even does Koenig name lookup
and warns of future errors once the C++ standard is
fully enforced.

I fixed some glitches in the code base detected by this
compiler and commited the fixes back when the cvs
repository was still at LANL.  But there is still a fairly
major thing preventing the Pooma library from building
under aCC.  It gets unhappy with the usage of the enum
"wildcard" in the Domain classes.  These classes define
an enumerator called "wildcard" and set the value to
either 1 or 0 to indicate if the Domain is a wildcard type
of domain.  Then there are function templates taking a
bool template argument and specialized for "true" or
"false" that do something different depending upon
whether a Domain is a wildcard type of domain or not.
So you see the expression "(wildcard==1)" being passed
as a template argument to these functions.  The aCC
alternately complains that either "wildcard" is not defined
in the current context or that there is no appropriate
operator== defined to evaluate the expression.

I'm not really sure if the aCC compiler is correct in its
complaints or not.  For example, is the compiler supposed
to look in the namespace of a base class for enumerator
definitions?  The aCC compiler seemed happier if "wildcard"
was qualified by the name of the class in which it was
defined.  With respect to comparisons between enumerators
and literal int's, you are supposed to compare like types by
promoting the int to the enumeration type.  Unfortunately,
most of our Pooma enumerators don't have an explicit
enumeration type, because we write them as

enum { wildcard = 0 };

I'm not sure how to go about fixing this problem.  It looks like
there are random places in the code where we have cast the
enumerator to be an int so that the comparison works.  This is
a pretty ugly solution.

I hate using these enums because different compilers seem to
treat them differently.  An alternative would be to define a
static bool "wildcard" in these classes, set it to "true" or "false",
and then pass that as the template argument.  But as I recall,
there was some problem with the Metrowerks compiler that
made this not a viable option.  I guess I am wondering if that
problem still exists or whether it would be OK to overhaul
the Domain classes to use static data types instead of enums.
The one drawback to this approach that I see is you have to
add some compiled source file that initializes these static
variables.  You can't just stick this in the class definition.

On the other hand, if you think the aCC compiler is full of
it and there is nothing at all wrong with this code in the
Domain sources, please let me know that, too.  I am on a list
for developers using aCC, and I can report compiler problems.
But I had a hard time trying trim down the problems in the
Domain sources to something simple I could submit as a bug
report for the HP technical support group.

For a specific example of the sort of thing aCC is unhappy
with, take a look at src/Domain/Contains.h, line 174.  A
static member function of the class template ContainsDomainSingle
is being invoked, with "(USN==0)" given as the third template
argument.  The aCC compiler gives the following error:

Non-type template arguments must be integral constant expressions, addresses
of
objects or functions with external linkage, or static class members.

The error goes away if I make "USN" a static const int data
member of class ContainsDomain and initialize its value as
DomainTraits<T1>::unitStride.  The code would be simpler
if DomainTraits<T1>::unitStride were already a static bool,
making the comparison with zero unnecessary.  There are
zillions of these sorts of things littered throughout the
Domain code.

Regards, Julian C.



--
Dr. Julian C. Cummings                       E-mail:
address@hidden
California Institute of Technology           Phone:  626-395-2543
1200 E. California Blvd., Mail Code 158-79   Fax:    626-584-5917
Pasadena, CA 91125




reply via email to

[Prev in Thread] Current Thread [Next in Thread]