[pdal] Alignment issues of getField and friends

Howard Butler hobu.inc at gmail.com
Wed Oct 5 10:54:24 EDT 2011


Michael,

I was testing out compiling PDAL with clang and it throws a number of cast alignment warnings related to our templated getField calls:

> In file included from /Users/hobu/dev/git/pdal/src/PointBuffer.cpp:35:
> /Users/hobu/dev/git/pdal/src/../include/pdal/PointBuffer.hpp:239:13: warning: cast from 'boost::uint8_t *'
>       (aka 'unsigned char *') to 'short *' increases required alignment from 1 to 2 [-Wcast-align]
>     return *(T*)p;
>             ^~~~~
> /Users/hobu/dev/git/pdal/src/PointBuffer.cpp:198:31: note: in instantiation of function template specialization
>       'pdal::PointBuffer::getField<short>' requested here
>                     output += STRINGIFY(GETFIELDAS(boost::int16_t));
>                               ^
> /Users/hobu/dev/git/pdal/src/PointBuffer.cpp:198:41: note: instantiated from:
>                     output += STRINGIFY(GETFIELDAS(boost::int16_t));
>                                         ^
> /Users/hobu/dev/git/pdal/src/PointBuffer.cpp:173:23: note: instantiated from:
> #define GETFIELDAS(T) getField<T>(pointIndex, fieldIndex)
>                       ^
> In file included from /Users/hobu/dev/git/pdal/src/PointBuffer.cpp:35:
> /Users/hobu/dev/git/pdal/src/../include/pdal/PointBuffer.hpp:239:13: warning: cast from 'boost::uint8_t *'
>       (aka 'unsigned char *') to 'unsigned short *' increases required alignment from 1 to 2 [-Wcast-align]
>     return *(T*)p;
>             ^~~~~
> /Users/hobu/dev/git/pdal/src/PointBuffer.cpp:208:31: note: in instantiation of function template specialization
>       'pdal::PointBuffer::getField<unsigned short>' requested here
>                     output += STRINGIFY(GETFIELDAS(boost::uint16_t));
>                               ^
> /Users/hobu/dev/git/pdal/src/PointBuffer.cpp:208:41: note: instantiated from:
>                     output += STRINGIFY(GETFIELDAS(boost::uint16_t));
>                                         ^
> /Users/hobu/dev/git/pdal/src/PointBuffer.cpp:173:23: note: instantiated from:
> #define GETFIELDAS(T) getField<T>(pointIndex, fieldIndex)
>                       ^
> In file included from /Users/hobu/dev/git/pdal/src/PointBuffer.cpp:35:
> /Users/hobu/dev/git/pdal/src/../include/pdal/PointBuffer.hpp:239:13: warning: cast from 'boost::uint8_t *'
>       (aka 'unsigned char *') to 'int *' increases required alignment from 1 to 4 [-Wcast-align]
>     return *(T*)p;


 http://stackoverflow.com/questions/2741787/warning-cast-increases-required-alignment has something to say about this, but the memcpy has the potential to be a performance killer unless the implementation is smart in some way. These alignment issues would be real if we were to move to a Power7 or something (not outside the realm of possibility for this kind of software/problem domain).  What should we do?

Howard


More information about the pdal mailing list