Variable arguments in C, how to get values with a generic type?

前端 未结 6 1628
花落未央
花落未央 2020-12-01 21:00

I\'m trying to use C stdarg.h lib, with a generic type. The type int, is my generic type > to understand it, please, hold reading. So, my problem is:

I have a functi

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 21:50

    Try u?intptr_t, which is defined in stdint.h. This is an integer which is guaranteed to be big enough to hold a pointer.

    You might also want to think about what happens when you pass a floating point number; it is converted to and passed as a double. If your program is expecting an int this will destroy its view of the stack. Ouch. And the compiler cannot catch this.

    And your function, as defined, has (barring any bit-encoding in paramN, in which case it should be an enum or bitfield, or, at least, unsigned) no way of knowing what the type of parameters it receives are, and as such is unlikely to be able to do anything useful with them. C has no run-time type information on its objects.

    What, exactly, are you trying to do?

提交回复
热议问题