Re: macro help



On Sun, 30 Sep 2007 04:14:19 -0700, William Pursell wrote:

On 30 Sep, 10:26, inftoc...@xxxxxxxxx wrote:
I wrote a macro to read 8 bytes from a byte stream. Am not
sure if it is working ok. Can anyone please point out if there looks
to be a problem!

#define READ64(b) ( (uint64_t(*b)) << 56) + ((uint64_t(*(b+1))) << 48)
+ ((uint64_t(*(b+2))) << 40) +((uint64_t(*(b+3))) << 32)+((uint64_t(*(b
+4))) << 24) + (( uint64_t(*(b+5))) << 16) + (( uint64_t(*(b+6))) <<
8) + ( *(b+7))

Here b is a pointer to an unsigned char.

Lots of problems:

The endianness of the machine will have
an impact, certainly.

I think he did that to have the same format on all machines.
Otherwise he could use memcpy().
--
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.

.



Relevant Pages

  • Re: The usage of %p in C
    ... It prints a pointer. ... likelyhood, depend on how pointers are usually printed on your platform. ... a hamburger is better than eternal happiness. ...
    (comp.lang.c)
  • Re: what is %p format specifier indicates in the printf statement?
    ... it is to print a pointer. ... The format of that isn't specified in the standard ... a hamburger is better than eternal happiness. ...
    (comp.lang.c)
  • Re: how can I return nothing?
    ... and I remember a "signum" function that does just this on my HP 48 ... and 312.34i all have sign 0, or we use the totally useless csgn ... a hamburger is better than eternal happiness. ...
    (comp.lang.c)
  • Re: using 64-bit integers on 32-bit machine
    ... Also "%x" is the conversion specifier for unsigned int (often 32 ... a hamburger is better than eternal happiness. ...
    (comp.lang.c)
  • Re: array index type
    ... It ain't broken (or, at least, that isn't the reason why it's ... IIRC MS never claimed to even try to conform to C99 (and ... a hamburger is better than eternal happiness. ...
    (comp.lang.c)