Small error in programming docs

bridged with qnx.development_tools
Post Reply
Evan Hillas

Small error in programming docs

Post by Evan Hillas » Sun Apr 03, 2005 9:13 pm

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 *===---

Robert Krten

Re: Small error in programming docs

Post by Robert Krten » Mon Apr 04, 2005 4:38 pm

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 :-)

Cheers,
-RK

Steve Reid

Re: Small error in programming docs

Post by Steve Reid » Mon Apr 04, 2005 6:25 pm

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
------------------------------------------

Chris Herborth

Re: Small error in programming docs

Post by Chris Herborth » Mon Apr 04, 2005 8:52 pm

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 :-)
Always test your code! :-)

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

Post Reply

Return to “qnx.development_tools”