[comp.lang.c] Byte order in tightly coupled system.

andy@research.canon.oz.au (Andy Newman) (06/17/91)

We have a rather interesting problem with a system we are putting
together and were wondering if others had any experience with any
similar situations.

Basically we have a tightly coupled (i.e., shared memory) system
with two processors, one little-endian, the other big-endian.
We were going to fix it in hardware but that didn't work as
expected so its up to us software people to attack it.

The system transfer *lots* of complex data structures between the
two processors (mainly in one direction, big-endian to
little-endian). There's certainly no problem in providing some
macros that read and write different primitive types but this
is a little low level. We thought about having macros that check
the size of an object and apply the appropriate byte swapping (yes
this can be fooled with certain structures) but weren't impressed
with the possibility of side effects and the great risk of people
making mistakes at 2am in the morning.

We thought about a pre-processor that would do the necessary magic
but in the general case you have to parse C properly and understand
type declarations. We could limit what is legal to simplify things
but we'd rather not.

Before we do anything ourselves has anyone developed any tools for
dealing with this sort of situation? Any ideas would be appreciated.

-- 
Andy Newman (andy@research.canon.oz.au)