Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 970
vmonteco Avatar asked May 22 '17 22:05

vmonteco


1 Answers

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.

like image 126
user2357112 supports Monica Avatar answered Sep 28 '22 00:09

user2357112 supports Monica