Small error in programming docs

Below is a quote from file:///usr/qnx630/target/qnx6/usr/help/product/neutrino/prog/freedom.html

The author got the orientation reversed. The correct printf result of big-endian is “0x12” and for little-endian it’s “0x78”.

—===* SNIP *===—

Typecast mangling

Consider the following code:

func ()
{
long a = 0x12345678;
char *p;

p = (char *) &a;
printf ("%02X\n", *p);
}

On a big-endian machine, this will print the value “0x78”; on a little-endian machine it will print “0x12”. This is one of the big (pardon the pun) reasons that typecasts are generally frowned upon by structured programmers.

—===* SNIP *===—

Evan Hillas <evanh@clear.net.nz> wrote:

Below is a quote from file:///usr/qnx630/target/qnx6/usr/help/product/neutrino/prog/freedom.html

The author got the orientation reversed. The correct printf result of big-endian is “0x12” and for little-endian it’s “0x78”.

—===* SNIP *===—

Typecast mangling

Consider the following code:

func ()
{
long a = 0x12345678;
char *p;

p = (char *) &a;
printf ("%02X\n", *p);
}

On a big-endian machine, this will print the value “0x78”; on a little-endian machine it will print “0x12”. This is one of the big (pardon the pun) reasons that typecasts are generally frowned upon by structured programmers.

—===* SNIP *===—

Sorry about that :slight_smile:

Cheers,
-RK

Evan Hillas <evanh@clear.net.nz> wrote:

Below is a quote from file:///usr/qnx630/target/qnx6/usr/help/product/neutrino/prog/freedom.html

The author got the orientation reversed. The correct printf result of big-endian is “0x12” and for little-endian it’s “0x78”.

I’ll create a docs PR. Thanks for pointing this out.


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

Robert Krten wrote:

Evan Hillas <> evanh@clear.net.nz> > wrote:

Below is a quote from file:///usr/qnx630/target/qnx6/usr/help/product/neutrino/prog/freedom.html

The author got the orientation reversed. The correct printf result
of big-endian is “0x12” and for little-endian it’s “0x78”.

Sorry about that > :slight_smile:

Always test your code! :slight_smile:


Chris Herborth (cherborth@qnx.com)
Never send a monster to do the work of an evil scientist.