[Insight-users] how does ITK affect the compiling process.

Luis Ibanez luis.ibanez at kitware.com
Wed Aug 11 20:27:44 EDT 2004


Hi Kexiang,

Visual C++ is not compliant with a
basic feature of the C++ standard:


    In a for loop, the scope of the
    variables declared inside the
    parenthesis should be limited
    to the body of the for loop.


for VisualStudio, by default,

    for(int i=0; i<N; i++)
      {
      }

is equivalent to

    int i;
    for(i=0; i<N; i++)
      {
      }


This is wrong according to the standard,
but it is one of those luxuries that you
can afford when you are a monopoly  :-)


In a gesture of remorse, VisualStudio
offers an option for making the compiler
do the right thing

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcrefzcforscope.asp

The relevant compilation options are

    /Zc
    /Za

and you can also use the precompiler pragma

      "conform"

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vcrefConform.asp



If you want to write portable code
you should assume that the scope of
the for loop variables is restricted
to the body of the loop.



Regards,


    Luis



--------------------
Kexiang Wang wrote:

> I play under VS6 (sp5)
> 
> when I include "iktImage.h" in the following example as:
> 
> #include "itkImage.h"
> 
> int main()
> {
>   int a = 0;
>   for (int i = 0; i< 10; i++)
>   {
> 	a += i;
>   }
> 
>   for (int i = 0; i < 10; i++)
>   {
> 	a -= i;
>   }
>   return 0;
> }
> 
> It's OK. 
> 
> But when i remove the #include "itkImage.h". 
> there is an error
> error C2374: 'i' : redefinition; multiple initialization
>         e:\work\test\main.cpp(6) : see declaration of 'i'
> 
> why?
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 






More information about the Insight-users mailing list