[Insight-developers] Borland C++ compiler and enums

Miller, James V (CRD) millerjv@crd.ge.com
Mon, 4 Feb 2002 14:21:14 -0500


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C1ADB0.75E1C772
Content-Type: text/plain

We can defined a macro so code that looked like
 
typedef Point<TScalarType, SpaceDimensions> InputPointType;

becomes
 
typedef Point<TScalarType,  ITK_ENUM(SpaceDimensions)> InputPointType;
 
ITK_ENUM can preprend the necessary information to the argument.  One implementation could be
 
#if defined(__BORLANDC__)
#define ITK_ENUM(x) (Self::x)
#else
#define ITK_ENUM(x) x
#endif

This would mean the ITK_ENUM could only be referenced within an ITK class declaration (where a valid
Self is defined).
 
This works but it requires surround the actual enum with parentheses.  It would be nicer if ITK_ENUM
could behave like ITK_TYPENAME, i.e.
 
typedef Point<TScalarType,  ITK_ENUM SpaceDimensions> InputPointType;


-----Original Message-----
From: Bill Hoffman [mailto:bill.hoffman@kitware.com]
Sent: Monday, February 04, 2002 10:28 AM
To: Miller, James V (CRD)
Subject: Re: [Insight-developers] Borland C++ compiler and enums


I forget which compiler forced us to use the enum and not the template
parameter directly?

What if we use a static_cast on the enum?
static_cast<int>(SpaceDimensions)

-Bill


At 09:43 AM 2/4/2002 -0500, you wrote:


We have identified the source of many of the errors when we build ITK with the Borland compiler.
Here is a snippet of
code
  
template <class TScalarType=double,   unsigned int NDimensions=3>
class foo
{
  enum { SpaceDimension      = NDimensions,
             ParametersDimension = NDimensions };
  typedef Point<TScalarType, SpaceDimensions> InputPointType;
  OutputPointType     TransformPoint(const InputPointType  &point ) const;
}
 
When compiling TransformPoint, the Borland compiler uses a Point<double, 0> as the argument instead
of a Point with the proper dimension.
 
The Boost web site says the Borland compiler does not recognize an enum as an integral type
unless it is fully qualified.  If we replace the point typedef with
 
  typedef Point<TScalarType, ::itk::ScaleTransform::SpaceDimension> InputPointType;
 
everything works, and if we use the template parameter directly, i.e.
 
  typedef Point<TScalarType, NDimensions> InputPointType;
 
everything works.

Does anyone know a work around for this problem? If we use the template parameter directly, then we
loose some
the context of whether something is a particular dimension because of the its "space" vs its
"parameterization". Fully spec'ing out the enum wherever it is used seems to be quite a hassle.
 
Is it worth the effort to get the Borland compiler to build Insight?  Since it is a free compiler,
supporting it may allow more students to use the toolkit.


Jim Miller 
_____________________________________
Visualization & Computer Vision
GE Corporate Research & Development
Bldg. KW, Room C218B
P.O. Box 8, Schenectady NY 12301

millerjv@crd.ge.com < mailto:millerjv@crd.ge.com <mailto:millerjv@crd.ge.com> >
(518) 387-4005, Dial Comm: 8*833-4005, 
Cell: (518) 505-7065, Fax: (518) 387-6981 

 



------_=_NextPart_001_01C1ADB0.75E1C772
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2>We can defined a 
macro so code that looked like</FONT></SPAN></DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2><FONT 
color=#000000>typedef Point&lt;TScalarType, SpaceDimensions&gt; 
InputPointType;</FONT><BR></FONT></SPAN></DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff 
size=2>becomes</FONT></SPAN></DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2><FONT 
color=#000000>typedef Point&lt;TScalarType,&nbsp; ITK_ENUM(SpaceDimensions)&gt; 
InputPointType;</FONT></FONT></SPAN></DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2><FONT 
color=#000000></FONT></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2><FONT 
color=#000000>ITK_ENUM can preprend the necessary information to the 
argument.&nbsp; One implementation could be</FONT></FONT></SPAN></DIV>
<DIV><SPAN class=739281619-04022002><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff 
size=2></FONT></SPAN><SPAN class=739281619-04022002><FONT color=#0000ff 
size=2>#if defined(__BORLANDC__)<BR>#define ITK_ENUM(x) 
(Self::x)<BR>#else<BR>#define ITK_ENUM(x) x<BR>#endif<BR></FONT></SPAN></DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2>This would mean 
the ITK_ENUM could only be referenced within an ITK class declaration (where a 
valid Self is defined).</FONT></SPAN></DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2>This works but it 
requires surround the actual enum with parentheses.&nbsp; It would be nicer if 
ITK_ENUM</FONT></SPAN></DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2>could behave like 
ITK_TYPENAME, i.e.</FONT></SPAN></DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2>
<DIV><SPAN class=739281619-04022002><FONT color=#0000ff size=2><FONT 
color=#000000>typedef Point&lt;TScalarType,&nbsp; ITK_ENUM SpaceDimensions&gt; 
InputPointType;</FONT></FONT></SPAN></DIV></DIV>
<DIV><BR></DIV></FONT></SPAN>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> Bill Hoffman 
  [mailto:bill.hoffman@kitware.com]<BR><B>Sent:</B> Monday, February 04, 2002 
  10:28 AM<BR><B>To:</B> Miller, James V (CRD)<BR><B>Subject:</B> Re: 
  [Insight-developers] Borland C++ compiler and enums<BR><BR></FONT></DIV>I 
  forget which compiler forced us to use the enum and not the 
  template<BR>parameter directly?<BR><BR>What if we use a static_cast on the 
  enum?<BR><FONT 
  size=2>static_cast&lt;int&gt;(SpaceDimensions)<BR><BR></FONT>-Bill<BR><BR><BR>At 
  09:43 AM 2/4/2002 -0500, you wrote:<BR>
  <BLOCKQUOTE class=cite cite type="cite"><FONT size=2>We have identified the 
    source of many of the errors when we build ITK with the Borland 
    compiler.&nbsp; Here is a snippet of</FONT><BR><FONT 
    size=2>code</FONT><BR><FONT size=2>&nbsp; </FONT><BR><FONT size=2>template 
    &lt;class TScalarType=double,&nbsp;&nbsp; unsigned int 
    NDimensions=3&gt;<BR>class foo</FONT><BR><FONT size=2>{</FONT><BR><FONT 
    size=2>&nbsp; enum { SpaceDimension&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 
    NDimensions,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    ParametersDimension = NDimensions };<BR>&nbsp; typedef Point&lt;TScalarType, 
    SpaceDimensions&gt; InputPointType;<BR>&nbsp; 
    OutputPointType&nbsp;&nbsp;&nbsp;&nbsp; TransformPoint(const 
    InputPointType&nbsp; &amp;point ) const;<BR>}</FONT><BR>&nbsp;<BR><FONT 
    size=2>When compiling TransformPoint, the Borland compiler uses a 
    Point&lt;double, 0&gt; as the argument instead of a Point with the proper 
    dimension.</FONT><BR>&nbsp;<BR><FONT size=2>The Boost web site says the 
    Borland compiler does not recognize an enum as an integral 
    type</FONT><BR><FONT size=2>unless it is fully qualified.&nbsp; If we 
    replace the point typedef with</FONT><BR>&nbsp;<BR><FONT size=2>&nbsp; 
    typedef Point&lt;TScalarType, ::itk::ScaleTransform::SpaceDimension&gt; 
    InputPointType;</FONT><BR>&nbsp;<BR><FONT size=2>everything works, and if we 
    use the template parameter directly, i.e.</FONT><BR>&nbsp;<BR><FONT 
    size=2>&nbsp; typedef Point&lt;TScalarType, NDimensions&gt; 
    InputPointType;</FONT><BR>&nbsp;<BR><FONT size=2>everything 
    works.<BR><BR>Does anyone know a work around for this problem? If we use the 
    template parameter directly, then we loose some</FONT><BR><FONT size=2>the 
    context of whether something is a particular dimension because of the its 
    "space" vs its "parameterization". Fully spec'ing out the enum wherever it 
    is used seems to be quite a hassle.</FONT><BR>&nbsp;<BR><FONT size=2>Is it 
    worth the effort to get the Borland compiler to build Insight?&nbsp; Since 
    it is a free compiler, supporting it may allow more students to use the 
    toolkit.<BR><BR></FONT><BR><FONT face="Comic Sans MS" color=#000080><B>Jim 
    Miller</B></FONT> <BR><FONT face=arial color=#ff0000 
    size=2><B><I>_____________________________________</I></B></FONT><BR><FONT 
    face=arial size=1><I>Visualization &amp; Computer Vision<BR>GE Corporate 
    Research &amp; Development<BR>Bldg. KW, Room C218B<BR>P.O. Box 8, 
    Schenectady NY 12301<BR><BR></FONT><FONT face=arial color=#0000ff 
    size=1><U>millerjv@crd.ge.com &lt;<A 
    href="mailto:millerjv@crd.ge.com">mailto:millerjv@crd.ge.com</A>&gt;</U></I></FONT><BR><FONT 
    face=arial size=1><I>(518) 387-4005, Dial Comm: 8*833-4005, 
    </I></FONT><BR><FONT face=arial size=1><I>Cell: (518) 505-7065, Fax: (518) 
    387-6981</I></FONT> <BR><BR>&nbsp;<BR></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C1ADB0.75E1C772--