Home > OS >  define 32bit on 64bit
define 32bit on 64bit

Time:02-10

i have some C files here (you don't need to know what's inside), it's in stable 32bit mode (with gcc -m32), now i want to do more 64bit (gcc -m64) it has some minor bugs\

  • question:
    so how to use a 32bit C number (how 32bit works), on 64bit\
  • more understandable explanation: i want to use 32bit in 64bit mode (-m64, there is some way works 32bit C cannot work in 64bit C)
    The most common error about this problem:
    "Cast to pointer from integer of different size"
    I really need help!\

CodePudding user response:

"Cast to pointer from integer of different size"

Oh no. Go through your code and get rid of all casts between pointer and integer that don't convert from or to intptr_t, uintptr_t, or ptrdiff_t. If you convert between pointer and other-sized integer it won't work no matter how many layers of indirection you use.

Once you've done that and you still need certain-sized integers for I/O reasons use the definitions from stdint.h:

int16_t: signed 16 bit integer
uint16_t: unsigned 16 bit integer
int32_t: signed 32 bit integer
uint32_t: unsigned 32 bit integer
int64_t: signed 64 bit integer
uint64_t: unsigned 64 bit integer

Keep size_t for array sizes, don't use it in on-disk formats. It changes.

  •  Tags:  
  • c gcc
  • Related