为函数指定argtypes

So after reading the answers answer 1 and answer 2, I was curious about always having to set argtypes on a function. The answers state that you should always specify the argtypes, i.e:

my_func.argtypes = [ctypes.c_int]
my_func(1)

否则,如果传递错误的大小变量,则可能会出错。

但是让我们假设我总是这样做:

my_func(ctypes.c_int(1))

Is this well defined? Does setting argtypes do anything more than what is achieved by always specifying the ctypes of arguments when you call the function (other than providing for less typing)?

评论