Larry's Notebook

August 8, 2011

Endianness Issues

Filed under: C/C++, computer architecture, embedded systems, programming — larryang @ 2:14 PM

There are 0010 0000 kinds of people in the world: Those that understand the difference between Big Endian and Little Endian, and those that do not.

My own endianness experience falls into roughly three categories: sharing binary data between heterogeneous processors, in protocols (most famous: TCP/IP) and in TDD unit testing C code. The last one is what prompted this blog post.

Solutions? For more readable, portable code, I’m avoiding macro based solutions. There is a tools based approach: Detecting Endian Issues with Static Analysis Tools. Sometimes, I’ll get lucky and the processor is able to handle both such as some DSPs.

One method for TDD for embedded systems tests the same source code on both the development platform and the target platform. For my personal embedded project, each platform had different endianness. I used a wrapper function whose implementation was determined by the compiler preprocessor. On the host platform (Intel Linux) I used byte-by-byte operations. On the target platform, I used intrinsic functions to operate on multiple byte-sized data.

This problem should be addressed at the architecture and protocol level and highlights the importance of test vectors which will show errors when the endianess is wrong.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: