[Insight-developers] Fixed width integer types, itkIntTypes, and portable 64-bit integer

Bradley Lowekamp blowekamp at mail.nih.gov
Mon Dec 7 12:03:32 EST 2009


On Dec 7, 2009, at 9:19 AM, Brad King wrote:
> 
> FYI, the actual names of the KWSys types in ITK would be of the form:
> 
>  itksysFundamentalType_U?Int(8|16|32|64)
> 
> However, these were not meant for direct use.  They are meant as
> try-compile results with out-of-the-way names that can be typedef'd
> as needed.

I had a concern about apple's universal builds and the size of long being check as a try compile. Fortunately it appear that it uses a couple of compile time checks to determine the sizes, which should be more robust, then falls back to the try-compile approach.

> 
> The problem with <stdint.h> (or really <cstdint> for future C++) is that
> providing compatibility with compilers that do not provide it must be done
> carefully to avoid namespace violations.  I'm aware of several projects
> that just typedef int32_t in the global namespace of public headers :(
> We need a better solution.
> 
> I suggest that we define the same types that stdint.h defines, except
> put them in the itk:: namespace.  We can use stdint.h where available
> and fall back on KWSys FundamentalType to get the types elsewhere:
> 
> // Common/itkStdInt.h
> #ifdef ITK_HAVE_STDINT_H
> # include <stdint.h>
> namespace itk {
>  typedef ::int32_t int32_t; // OR using ::int32_t;
>  typedef ::int64_t int64_t;
>  ...
> }
> #else
> # include <itksys/FundamentalType.h>
> namespace itk {
>  typedef ::itksysFundamentalType_Int32 int32_t;
>  typedef ::itksysFundamentalType_Int64 int64_t;
>  ...
> }
> #endif

This makes sense. 

Also there is the issue of when we define that there is a 64-bit integer. I would be inclined to only define it when it is fully functioning; that is it can be converted to double and is printable with c++ stream.

> 
> This approach will work everywhere, avoids defining names outside the
> "itk::" namespace, and allows ITK code to use the types without any
> qualification.  When <cstdint> is standard in the future, we can switch
> the definitions to
> 
> #include <cstdint>
> namespace itk {
>  using ::std::int32_t;
>  using ::std::int64_t;
>  ...
> }
> 
> I think the same approach is already in use by the Boost community.
> 
> -Brad K

========================================================
Bradley Lowekamp  
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20091207/3074c560/attachment.htm>


More information about the Insight-developers mailing list