Yeah, load the whole fucking file into memory to read two fields.
Name:
Anonymous2008-06-11 8:55
>>13
memory is cheap. lines of forcibly indented code are expensive.
Name:
Anonymous2008-06-11 9:11
>>13
He's going to work with all this data so it's ok.
Name:
Anonymous2008-06-11 10:46
i am a heron. i ahev a long neck and i pick fish out of the water w/ my beak. if you dont repost this comment on 10 other pages i will fly into your kitchen tonight and make a mess of your pots and pans
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
If by "not portable" you mean the size of the types, just use the appropriate size (C99 has some defined, I never bother to use them because I know what size my ints/shorts/longs are for the platform I'm developing on.)
>>24,26
It doesn't have to care about endianness as it performs the same operation on both little-endian and big-endian machines. int should be changed to long for maximum portability though.
For efficiency, you can replace the separate arguments with a pointer and use conditional compilation: static long fourchar2int(unsigned char* b)
{
#ifdef X86
return *((int*) b);
#else
if (b[3] & 0x80) {
return (~b[3] & 0xff) * -16777216
+ (~b[2] & 0xff) * -65536
+ (~b[1] & 0xff) * -256
+ (~b[0] & 0xff) * -1
- 1;
} else {
return b[3] * 16777216
+ b[2] * 65536
+ b[1] * 256
+ b[0] * 1;
}
#endif
}