函数指针的 uintptr_t/intptr_t 等价物?

Equivalent of uintptr_t/intptr_t for pointers to functions?

Afaik uintptr_tintptr_t 可用于保存指向 void 的任何指针。因此,这些类型可用于存储指向 data.

的指针

在 C99 或更高版本中,是否有类似的有符号和无符号整数类型能够保存指向函数的指针?

不,没有这样的类型。

函数指针只能可靠地转换为其他函数指针类型(然后,仅在指向正确的函数类型时取消引用)。

C 中函数指针到整数的转换包含在 6.3.2.3/6 中:

Any pointer type may be converted to an integer type. Except as previously specified, the result is implementation-defined. If the result cannot be represented in the integer type, the behavior is undefined. The result need not be in the range of values of any integer type.

请注意,即使整数类型足够大,转换为整数并返回函数指针也不能保证检索到原始函数指针。

在 C++ 中,文本位于 [expr.reinterpret.cast] 第 4 点和第 6 点。行为类似,但它明确保证如果存在足够大的整数,则将函数指针转换为整数并返回再次检索原始函数指针。