[Insight-developers] more VC++ idiosyncrasies

Miller, James V (CRD) millerjv@crd.ge.com
Mon, 4 Dec 2000 07:57:42 -0500


The C and C++ standards have changed back and forth on this often enough that I can never remember
what the current "standard" is for loop variables.  At one time, loop variables were limited in scope
to the loop, so the code referenced here was legal.

Rather than change the compiler option or use a #define to remap "for", I suggest we just change the
code so that we do not use this construct, i.e. do not declare the same variable in the
initialization clause of a "for" loop multiple times in routine.

So the code,

for (int i=0; i < ...; i++)
  {
  // some code
  }

for (int i=0; i < ...; i++)
  {
  // some other code
  }

would be discouraged.  But code like

for (int i=0; i < ...; i++)
  {
  // some code
  }

for (i=0; i < ...; i++)
  {
  // some other code
  }

would still be legal ("i" is only declared once).






-----Original Message-----
From: Lydia Ng [mailto:lng@statsci.com]
Sent: Friday, December 01, 2000 10:11 PM
To: insight-developers@public.kitware.com
Subject: [Insight-developers] more VC++ idiosyncrasies


Hi,

I get an error when I try to compile itkImportImageTest.cxx in VC++.
It complains about the redefinition of the loop variable i in
line 90 of itkShrinkImage.txx. The error message is attached below.

This is yet another C++ standard noncompliance problem,
worst still it happens intermittently as there is lots of other code
where the loop variable has been used more than once.

They have a fix in:
http://support.microsoft.com/support/kb/articles/Q167/7/48.ASP

where they suggest to either:
    a) set compiler option /Za

This causes more compile errors.

    b) #defining the "for" keyword as follows:
            #define for if(0); else for

The #defining seems to work.
If this is the only solution, we probably need to stick it
in some VC++ related makefile.

BTW, when I run itkImportImageTest in Release mode (after adding the
#define) I get an
access violation due to the CopyInformation() problem.
Running itkImportImageTest on Cygwin also results in an access violation
- but I haven't stepped through it to see if it the same problem.

Lydia

--------------------Configuration: itkImportImageTest - Win32
Release--------------------
Compiling...
itkImportImageTest.cxx
F:\lng\projects\Insight-clean\Insight/Code/Common\itkMultiThreader.h(233) :
warning C4251: 'm_SpawnedThreadActiveFlagLock' : class
'itk::SmartPointer<class itk::MutexLock>' needs to have dll-interface to be
used by clients of class 'itk::MultiThread
er'
F:\lng\projects\Insight-clean\Insight/Code/Common\itkProcessObject.h(342) :
warning C4251: 'm_Inputs' : class 'std::vector<class itk::SmartPointer<class
itk::DataObject>,class std::allocator<class itk::SmartPointer<class
itk::DataObject> > >' needs
to have dll-interface to be used by clients of class 'itk::ProcessObject'
F:\lng\projects\Insight-clean\Insight/Code/Common\itkProcessObject.h(348) :
warning C4251: 'm_Outputs' : class 'std::vector<class
itk::SmartPointer<class itk::DataObject>,class std::allocator<class
itk::SmartPointer<class itk::DataObject> > >' needs
 to have dll-interface to be used by clients of class 'itk::ProcessObject'
F:\lng\projects\Insight-clean\Insight/Code/Common\itkProcessObject.h(371) :
warning C4251: 'm_Threader' : class 'itk::SmartPointer<class
itk::MultiThreader>' needs to have dll-interface to be used by clients of
class 'itk::ProcessObject'
F:\lng\projects\Insight-clean\Insight/Code/Common\itkShrinkImage.txx(90) :
error C2374: 'i' : redefinition; multiple initialization

F:\lng\projects\Insight-clean\Insight/Code/Common\itkShrinkImage.txx(76) :
see declaration of 'i'
        C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(583) :
while compiling class-template member function 'void __thiscall
itk::ShrinkImage<class itk::Image<short,2,class
itk::ImportImageContainer<unsigned long,short> >,class itk::
Image<class itk::Scalar<short>,2,class itk::ValarrayImageContainer<unsigned
long,class itk::Scalar<short> > > >::ThreadedGenerateData(const class
itk::ImageRegion<2> &,int)'
Error executing cl.exe.

itkImportImageTest.exe - 1 error(s), 4 warning(s)



_______________________________________________
Insight-developers mailing list
Insight-developers@public.kitware.com
http://public.kitware.com/mailman/listinfo/insight-developers