You should return unsigned long long
and let the user decide what they want to do with the cast, especially if you want this to be generic.
I'd prefer a name such as u32tou64
, uinttoull
, or something more descriptive than combine. A lot of this will depend on your own naming standards, though.
Also, I'd consider being more pedantic:
return (((uint64_t) high) << 32) | ((uint64_t) low);
It's unlikely to make a difference because the code is essentially the same as yours, but it's easier to read and avoids extremely rare (but very troublesome to debug) casting issues. It may require a custom types header if your compiler doesn't support this type notation.
Also, consider making it a macro. There's little benefit to having it as a function - the operation itself will take far less time than the function call setup, call, and return, so the performance of a macro will be much higher. Further, it isn't going to take up much more program space than a function call, so there's little to gain by leaving it a real function.
|
rather than a logical or operator||
. \$\endgroup\$ – Adam Davis May 25 '11 at 18:15