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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.