'OSTypes' - nonportable? 
Author Message
 'OSTypes' - nonportable?

Hi all,

On the Macintosh, a long used as a set of four chars is used frequently
(referred to as OSTypes or derivatives thereof). I've been using this
approach for tag identifiers in a platform-independent data encoding
module, e.g.

    PIAddString( thePacket, 'name', loginName );

etc. Which has worked well with the quirk that even though the DEC
machines we have here are little endian, the OSType values are stored in
the exact same order as on the Mac, a big endian machine (ok ok, a 68k

This led me working this expression out:
    long x = 'abcd';
    printf( "%x", x );

on the DEC machines:

on the Mac:

...and this isn't because they're big/little endian because if I make x be
'abcd'+1 then on the mac, it becomes 'abde' and on unix it becomes 'bbcd'.
So as numbers, this char format is useless since it's nonportable! This is
a particular bummer for me because I wanted to do things like this:

    for( i = 0; i<numPapers; i++ )
        PIAddString( thePacket, 'papr'+i, paper[i] );

with the intent on the other end of doing:

    for( i = 0; i<numPapers; i++ )
        PIExtractString( thePacket, 'papr'+i, paper[i] );


Any ideas how I can get around this? it looks like four byte chars
represented like this was a latecomer in the C world and is a bit of a
hack really.

Thanks in advance.
.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
if a million monkeys had a million years        >  Julian Harris, Programmer   >
at a terminal they could eventually            >  Comp. Sci. Dept.     x8915  >
get two columns in Word                       >  The University of Auckland  >

Fri, 21 Feb 1997 10:37:50 GMT  
 [ 1 post ] 

 Relevant Pages 

1. '0', '1', '2', '3' ...???

2. MS-DOS NRO (an 'NROFF'- 'RNO'-like Source in C)

3. Clarification on method modifiers 'new', 'virtual', 'override'

4. System-dependent manifest constants (i.e., 'i386', 'mips', 'vax')

5. '+=' : conversion from 'int' to 'unsigned char', possible loss of data

6. {'a','b','\0'} not equivalent to "ab"??

7. A good translation of 'to marshal', 'marshal', 'marshalling' to German ?

8. Error 'Must declare variable '@xxxxxx'.

9. Looking for gcc/g++/egcs for TI 'c30, 'c40, 'c60

10. program doesn't see '\0'

11. Can't 'free'

12. TC's windows with 'curses'?


Powered by phpBB® Forum Software