🔴 哪几样在边界上走得通
⚠️ 这条路线**一个答案都不是耗时**。耗时跟机器、跟负载、跟编译器都有关,换台机器数字就变了。**能当答案的只有"走了多少步"和"两边结果一不一样"。**
import ctypes
# 能直接跨过去的,都是"两边都认识的那几样"
ok_int = int(ctypes.c_int(7).value == 7)
ok_double = int(abs(ctypes.c_double(1.5).value - 1.5) < 1e-9)
ok_bytes = int(ctypes.c_char_p(b"ab").value == b"ab")
# Python 的 list / dict 没有对应的 C 类型,递不过去
has_list_type = int(hasattr(ctypes, "c_list"))
has_dict_type = int(hasattr(ctypes, "c_dict"))
print(f"{ok_int}/{ok_double}/{ok_bytes}/{has_list_type}/{has_dict_type}")
全部评论