On 01/23/10 14:08, David Laight wrote:
On Sat, Jan 23, 2010 at 12:32:31PM +0100, Jean-Yves Migeon wrote:On 01/23/10 09:13, Christoph Egger wrote:On 23.01.10 02:53, Jean-Yves Migeon wrote: Jean, Manuel: We should introduce helper macros which hide the needed casts completely. This makes new code less error prone.It is something that is worth considering, although not as easy to fix as it seems.macros don't normally force you to write the correct code - especially if they cast their arguments.
Functions either in this case. See below.
inline functions can help, as can embedding an integral type within a structure - and then passing the structure by value.
Even if you have a function with a "correct" prototype, it can go wrong. #include <stdio.h> /* Some typedefs for clarity */ typedef unsigned long xen_pfn_t; /* as defined by Xen */ typedef unsigned long long paddr_t; /* 64 bits PDE/PTE for PAE */ paddr_t pfn_to_paddr(xen_pfn_t pfn) { return pfn << PAGE_SHIFT; } int main(void) { xen_pfn_t pfn = 0xf0000000; paddr_t pfn2 = 0xf0000000ULL; printf("1: %llx\n", pfn_to_paddr(pfn)); printf("2: %llx\n", pfn_to_paddr(pfn2)); return 0; } -- Jean-Yves Migeon jeanyves.migeon%free.fr@localhost