Please modify this MS specific C code to compile under gcc on both 32-bit & 64-bit platforma and produce the same output:
Pointer 1<<34 doesn't make sense on 32-bit platforms.
I also don't see how you can get the same output on 32-bit and 64-bit platforms when ALIGN_BITS depends on the pointer size (sizeof(void*) >> 1i64). The data or ALIGN_BITS would need to be changed.
On to the real question, you need the following to be configurable:
So here goes:
#include <stdio.h> /* **** For a system where a pointer is an unsigned long long: */ typedef unsigned long long uintptr_t; #define UINTPTR_CONST(p) ((uintptr_t)p##ULL) #define UINTPTRXf "llX" /* **** For a system where a pointer is an unsigned long: typedef unsigned long uintptr_t; #define UINTPTR_CONST(p) ((uintptr_t)p##UL) #define UINTPTRXf "lX" */ #define NOP_BITS 2 #define BIT_BITS 3 #define BYTE_BITS 14 #define NOP_MASK UINTPTR_CONST(0x00000003) #define BIT_MASK UINTPTR_CONST(0x00000007) #define BYTE_MASK UINTPTR_CONST(0x00003FFF) #define NOP_OFFSET 0 #define BIT_OFFSET (sizeof(void*) >> 1) #define BYTE_OFFSET (BIT_OFFSET + BIT_BITS) #define SLOT_OFFSET (BYTE_OFFSET + BYTE_BITS) void check_new(void* p) { register uintptr_t i = (uintptr_t)p; uintptr_t slot = ( i >> SLOT_OFFSET ); uintptr_t byte = ( i >> BYTE_OFFSET ) & BYTE_MASK; uintptr_t bit = ( i >> BIT_OFFSET ) & BIT_MASK; uintptr_t nop = ( i >> NOP_OFFSET ) & NOP_MASK; printf("address: %012p " "slot: %012p " "byte: %4"UINTPTRXf" " "bit: %4"UINTPTRXf" " "nop: %"UINTPTRXf"\n", p, (void*)slot, byte, bit, nop ); } int main(int argc, char *argv[]) { void* p; for ( p = (void*)UINTPTR_CONST(123456); p < (void*)(UINTPTR_CONST(1) << 34); p += (UINTPTR_CONST(1) << 29) ) check_new(p); return 0; }
In reply to Re: 64-bit *nix/gcc expertise required
by ikegami
in thread 64-bit *nix/gcc expertise required (THIS IS NOT OFF TOPIC!)
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |