Effective Use of C Pointers on the x86 - Embedded.com

Effective Use of C Pointers on the x86


Pointers, which can sometimes be a challenge to use, are especially problematical on the x86. In this article, the author steers around the difficulties with some pointers of his own.

Pointers are C's most powerful and most troublesome feature. This is true on any computer. On the Intel x86 series, additional problems can trip up even experienced C programmers. Most programmers learn these little “gotchas” one at a time. With a little understanding of what's going on under the hood and a walk through several ways in which this problem can show up, you can write C programs that don't stumble over the x86-specific pointer problems, all without compromising portability.

The problems with C pointers unique to the x86 family are the result of the x86's segmented architecture. In the first section, I'll describe how C pointers are implemented and how x86 pointers differ from C pointers. In the next two sections, I'll discuss the consequences of pointer overflow and under flow and how to avoid them. Finally, I'll describe huge pointers, which behave just like C pointers. If you don't have to deal with all the nonsense in the earlier sections, you can just skip to this section. Be aware that some serious costs are involved in huge pointers. After your program is running, you may want to come back and take a second look.

Click here to access PDF version of article.

Jeff Taylor writes in a variety of genres and languages. C and C++ are his native tongues and English is his first foreign language. After years of C's or worse in his English classes, he is about to have his revenge—two of his poems will be published in the premier issue of The Montserrat Review. He can be reached electronically at jltaylor@cyber-quest.com.

All material on this site Copyright © 2012
CMP Media Inc./UBM Electronics/UBM–All rights reserved.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.