MantisBT - ITK
View Issue Details
0005255ITKpublic2007-06-29 14:462008-01-25 10:13
Mathieu Coursolle 
Mathieu Coursolle 
normalminoralways
closedfixed 
 
 
0005255: Usage of id as a variable name causes error in Objective-C++ projects including some ITK headers.
Some ITK headers include files that declare variables named "id".

"id" is a reserved key-word in Objective-C and Objective-C++ to represent any pointer to an objective-C object.

An Objective-C++ application can mix both objective-C and C++ (ex: ITK).

Therefore, if an ITK header declares a variable named id, it produces a compiler error when that header is included in an Objective-C++ project.

A solution would be to replace all use of the "id" key-word in ITK included files and replace them by some alternative (ex: theId).

Example:

itkVectorContainer.h includes itkVectorContainer.txx which implements the following:

template <typename TElementIdentifier, typename TElement>
bool
VectorContainer< TElementIdentifier , TElement >
::IndexExists(ElementIdentifier id) const
{
  return (NumericTraits<ElementIdentifier>::IsNonnegative(id)
          && (id < this->VectorType::size()));
}

The following error is produced:
itkVectorContainer.txx:137: error: cannot find protocol declaration for ''
No tags attached.
Issue History
2007-08-14 17:14Sean McBrideNote Added: 0008464
2007-08-17 14:19Mathieu CoursolleNote Added: 0008504
2007-08-23 10:22Mathieu CoursolleAssigned ToLuis Ibanez => Mathieu Coursolle
2007-08-23 10:40Mathieu CoursolleNote Added: 0008613
2008-01-25 10:13Mathieu CoursolleStatusassigned => resolved
2008-01-25 10:13Mathieu CoursolleResolutionopen => fixed
2008-01-25 10:13Mathieu CoursolleNote Added: 0010297
2008-01-25 10:13Mathieu CoursolleStatusresolved => closed

Notes
(0008071)
Luis Ibanez   
2007-07-15 09:28   
We will need a dashboard submission in order to find all the "id" instances that conflict with Objective C++.
(0008464)
Sean McBride   
2007-08-14 17:14   
Luis, so far "all instances" is only 1 instance, so this problem does not seem widespread. Since it's just renaming a variable, we will commit this fix unless you object.

To be able to find these on a dashboard, we would need a .m and/or .mm source file (Objective-C and Objective-C++ respectively) that includes many/all itk headers. I suppose a test could be created that simply compiles such a file. If the file does not compile it is because there is a parse error in one of the headers, such as by having a variable named 'id'. But this test would need constant updating, everytime there is a new ITK header. Seems painful.
(0008504)
Mathieu Coursolle   
2007-08-17 14:19   
The following files have been changed to replace "id" by "identifier" to avoid any conflicts with the Objective-C keyword:

/Code/Common/itkVectorContainer.txx
/Code/Numerics/Statistics/itkHistogram.txx
/Code/Numerics/Statistics/itkListSampleBase.h
/Code/Numerics/Statistics/itkListSample.txx
/Code/Algorithms/itkEuclideanDistancePointMetric.txx
/Code/SpatialObject/itkMetaTubeConverter.txx
/Code/SpatialObject/itkMetaDTITubeConverter.txx
/Code/SpatialObject/itkMetaVesselTubeConverter.txx
/Code/SpatialObject/itkMetaBlobConverter.txx
/Code/SpatialObject/itkMetaLandmarkConverter.txx
/Code/SpatialObject/itkMetaLineConverter.txx
/Code/SpatialObject/itkSurfaceSpatialObject.txx
/Code/SpatialObject/itkMetaSurfaceConverter.txx
/Code/SpatialObject/itkMetaContourConverter.txx
/Code/Patented/itkActiveShapeModelCalculator.txx
/Code/Patented/itkActiveShapeModelGradientSearchMethod.txx

Objective-C++ header tests will later be added to ensure that no other
variables are named id in ITK included files.

A TRY_COMPILE directive checks if the compiler can compile objective-C++.
If so, Objective-C++ header tests are added and compiled if testing is enabled.
(0008613)
Mathieu Coursolle   
2007-08-23 10:40   
CMakeLists.txt was changed to add a TRY_COMPILE to test for Objective-C++ compiler (ITK_OBJCXX_COMPILER).

The following tests were added:

/CMake/itkTestObjCxxCompiler.mm
/Testing/Code/Algorithms/itkAlgorithmsHeaderObjCxxTest.mm
/Testing/Code/BasicFilters/itkBasicFiltersHeaderObjCxxTest.mm
/Testing/Code/Common/itkCommonHeaderObjCxxTest.mm
/Testing/Code/IO/itkIOHeaderObjCxxTest.mm
/Testing/Code/Numerics/itkNumericsHeaderObjCxxTest.mm
/Testing/Code/Numerics/NeuralNetworks/itkNeuralNetworksHeaderObjCxxTest.mm
/Testing/Code/Numerics/Statistics/itkStatisticsHeaderObjCxxTest.mm
/Testing/Code/Patented/itkPatentedHeaderObjCxxTest.mm
/Testing/Code/SpatialObject/itkSpatialObjectHeaderObjCxxTest.mm

The corresponding Testing folders CMakeListx.txt file have been modified to include those tests if an Objective-C++ compiler was found.
(0010297)
Mathieu Coursolle   
2008-01-25 10:13   
Tests have been ran with success:
http://www.itk.org/Testing/Dashboard/20080125-0100-Nightly/Dashboard.html [^]