[vtkusers] #Defines for Big or Little Endian

David Gobbi dgobbi at atamai.com
Fri Sep 1 12:09:30 EDT 2006


Mike Jackson wrote:
> On 9/1/06 11:19 AM, "David Gobbi" <dgobbi at atamai.com> wrote:
>
>   
>> Mike Jackson wrote:
>>     
>>> On 9/1/06 10:56 AM, "Sean McBride" <sean at rogue-research.com> wrote:
>>>
>>>   
>>>       
>>>> I believe vtkByteSwap is the only class that does anything like this.
>>>> You might want to search all the vtk code for "VTK_WORDS_BIGENDIAN" to
>>>> learn a little more about how vtk does swapping.
>>>>
>>>> Personally, I find Apple's APIs are much better named, but I believe
>>>> vtkByteSwap::Swap4BE(), for example, swaps a 4 byte value from host to big.
>>>>     
>>>>         
>>> No, actually vtkByteSwap::Swap4BE() does the swap period. It does not pay
>>> attention to if it actually _needs_ to be done. It just does it.
>>>   
>>>       
>> I don't understand what you're saying here.  Swap4BE will always do a
>> swap on a little-endian machine, and will never do a swap on a
>> big-endian machine.  So it only does the swap if the swap needs to be done.
>>
>> Likewise, Swap4LE will only do the swap on a big-endian machine.
>>
>> Are you sure that you are using these methods correctly?
>>
>>  - David  
>>     
>
> Nope.. Not that I wasn't using them correctly, I wasn't completely
> understanding what they did (Maybe it is those really verbose method names
> ;-) )
>  The trouble I think I would have is if in my own code I tested for
> VTK_WORDS_BIGENDIAN from vtkConfigure.h. That would mess up my code half the
> time when compiling for both PPC and Intel. The vtk libs that are compiled
> are already correct in that they will do the right thing on the right
> platform. 
>    In my own code however when testing for Endian-ness I should be using the
> gnu defines __LITTLE_ENDIAN__ and __BIG_ENDIAN__ instead. I believe this
> will get around the universal binary issue.
>   

As you already know, VTK_WORDS_BIGENDIAN is set at
configure time, not at compile time, so if you are cross-compiling
between big and small endian architectures, all I can say is
good luck and I hope you are successful!

In any case, if you are checking VTK_WORDS_BIGENDIAN before
applying the VTK swap methods, you are doing something wrong
because these methods already to the check internally.

 - David




More information about the vtkusers mailing list