小编Lig*_*ons的帖子

如何确定指针大小的预处理器C

我正在开发OpenGL的软件实现,而OpenGL似乎要求我返回32位指针。为了节省时间,我将其放入64位系统的C语言map中,以便从32位伪地址中检索64位指针。但是,在32位系统上,这会造成麻烦,因此我应该逐字使用指针。

这基本上是我要在共享标头中执行的操作:

#if <64-bit>
    #include <search.h>
    extern void * pointerTable;
    typedef struct {
          int key;
          void* value;
    } intPtrMap;

    inline int compar(const void *l, const void *r) {
        const intPtrMap *lm = l;
        const intPtrMap *lr = r;
        return lm->key - lr->key;
    }

    inline uint32_t allocate(size) {
        void* result = malloc(size);
        intPtrMap *a = malloc(sizeof(intStrMap));
        a->key = (uint32_t) result;
        a->value = result;
        tsearch(a, &pointerTable, compar);
        return (uint32_t) result;
    }

    inline int getPtr(ptr) {
        intPtrMap *find_a = malloc(sizeof(intPtrMap));
        find_a->key = ptr; …
Run Code Online (Sandbox Code Playgroud)

c pointers

5
推荐指数
1
解决办法
564
查看次数

标签 统计

c ×1

pointers ×1