[vtkusers] #Defines for Big or Little Endian
Mike Jackson
mike.jackson at imts.us
Fri Sep 1 12:03:00 EDT 2006
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
>
>
>> In Apples code for swapping Little To System for instance there is a
>> compiler check to see if the code is compiled for a Little Endian machine.
>> If it _is_ compiled for a Little Endian machine then the method simply
>> returns the argument that was passed in. If on the other hand the code was
>> compiled on a BIG endian machine then the actual swap will take place. This
>> is a nice optimization that takes place on your behalf with out any work on
>> your part.
>>
>> I am reading binary files that can be Big or Little Endian or either a Big
>> Or Little Endian machine. That is 4 combinations. If I use VTK's byte
>> swapping code I would have to write 4 versions of my code. One covering each
>> of the possibilities. By using API's such as those from Apple the compiler
>> can optimize 2 of those situations away for me so I only need to write 2
>> versions of my code.
>>
>> Unless in my newbie C++ knowledge I have completely missed something...
>>
>> Cheers
>>
>
As a follow up to my own post I think that in the vtkConfigure.h on OS X I
think that there needs to be something like:
/* Byte order. */
#if defined(__i386__) && defined(__GNUC__)
#undef VTK_WORDS_BIGENDIAN
#elif defined(__ppc__) && defined(__GNUC__)
#define VTK_WORDS_BIGENDIAN
#else
#error Do not know the endianess of this architecture
#endif
At the top. This is pretty much what Apple uses in there own files. Testing
is required.. Maybe put this into the next version of VTK to help out those
of us trying to compile universal binaries?
--
______________________________________________________________________
/ Mike Jackson Senior Research Engineer
| CTMD Group - Materials and Manufacturing Directorate - AFRL - WPAFB
| Innovative Management & Technology Services
| 2900 Presidential Dr, Suite 170 Fairborn Ohio 45324
More information about the vtkusers
mailing list