Pointer peril

Use of pointers in the C programming language is subject to a number of constraints, violation of which results in the dreaded undefined behaviour. If a situation with undefined behaviour occurs, anything is permitted to happen. The program may produce unexpected results, crash, or demons may fly out of the user’s nose.

Some of these rules concern pointer arithmetic, addition and subtraction in which one or both operands are pointers. The C99 specification spells it out in section 6.5.6:

When an expression that has integer type is added to or subtracted from a pointer, the result has the type of the pointer operand. […] If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined. […]

When two pointers are subtracted, both shall point to elements of the same array object, or one past the last element of the array object; the result is the difference of the subscripts of the two array elements.

In simpler, if less accurate, terms, operands and results of pointer arithmetic must be within the same array object. If not, anything can happen.
Continue reading

Shades of black

Some time ago now, I was looking for a new laptop. Having compared the technical specifications of a number of models, I turned my attention to the most important aspect: the colour. Everybody knows black is the best colour, but which particular shade of black? There are, apparently, quite a few to choose from.

While some may settle for the plain Black, others will demand something more distinguished. The musician, for instance, might find Piano Black more attractive, while Ebony Black has, perhaps, an organic touch. For a more “hi-tech” feeling, there is Carbon Black, and if that is insufficient, Ultimate Carbon should hopefully do the trick. The French-sounding Intense Noir might, I speculate, be designed to evoke quasi-artistic images, whereas Platinum Black to me rings mostly of expensive and hardly at all of black. The last entry on my list is Liquorice Black, for which interpretation I refer to those capable of ingesting this vile substance.

To this day I remain completely clueless regarding any actual variation in physical appearance, as for my purchase I selected black, plain and simple, and spent the difference on a RAM upgrade.

ARM inline asm secrets

Although I generally recommend against using GCC inline assembly, preferring instead pure assembly code in separate files, there are occasions where inline is the appropriate solution. Should one, at a time like this, turn to the GCC documentation for guidance, one must be prepared for a degree of disappointment. As it happens, much of the inline asm syntax is left entirely undocumented. This article attempts to fill in some of the blanks for the ARM target.
Continue reading

Hacking the Popcorn Hour C-200

Update: A new firmware version has been released since the publication of this article. I do not know if the procedure described below will work with the new version.

The Popcorn Hour C-200 is a Linux-based media player with impressive specifications. At its heart is a Sigma Designs SMP8643 system on chip with a 667MHz MIPS 74Kf as main CPU, several co-processors, and 512MB of DRAM attached. Gigabit Ethernet, SATA, and USB provide connectivity with the world around it. With a modest $299 on the price tag, the temptation to repurpose the unit as a low-power server or cheap development board is hard to resist. This article shows how such a conversion can be achieved.
Continue reading