Long long int on 32 bit machines

前端 未结 5 1026
野的像风
野的像风 2020-12-17 16:11

very simple question, I read that GCC supports long long int type. But how can make math operations with it, when CPU is 32 bit wide only?

5条回答
  •  温柔的废话
    2020-12-17 16:31

    Internally, the type is represented by a high-word and a low-word, like:

    struct long
    {
      int32 highWord;
      uint32_t lowWord;
    }
    

    The compiler needs to know if it is a 32bit or 64bit environment and then selects the right reprenstations of the number - if it is 64bit, it can be done natively, if it is 32bit, the compiler has to take care of the math between the high/lowword.

    If you have a look in math.h, you can see the functions used for this, and use them yourself. On an additional note, be aware of the difference between little-endian and big-endian (see wiki), the usage depends on the operating system.

提交回复
热议问题