Converting double to void* in C

后端 未结 3 1251
深忆病人
深忆病人 2020-11-30 14:24

I\'m writing an interpreter and I\'d like to be able to store whatever value a function returns into a void pointer. I\'ve had no problem storing ints and various pointers a

3条回答
  •  攒了一身酷
    2020-11-30 14:42

    On many systems a double is 8 bytes wide and a pointer is 4 bytes wide. The former, therefore, would not fit into the latter.

    You would appear to be abusing void*. Your solution is going to involve allocating storage space at least as big as the largest type you need to store in some variant-like structure, e.g. a union.

提交回复
热议问题