简体   繁体   中英

Detecting C types limits (“limits.h”) in python?

I've made a little test program in python to test some C functions in many cases. This python program use ctypes to import and use my C functions.

But I'd also like to test minimum and maximum values cases ( limits.h 's ULLONG_MAX for instance).

But since some of these limits can be system dependant, I'd prefer to avoid hard coding it in my program; I'd rather dynamically get it.

Is it possible to get these limits values in python?

I believe the closest you can get is

ctypes.sizeof(whatever_type)

which gives you the size of the type in bytes. For example, you can use ctypes.sizeof(ctypes.c_int) to figure out whether a byte is 4 bytes, 8, or some other weird number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM