Marvin Humphrey <[EMAIL PROTECTED]> writes: >Greets, > >Some of the algorithms I'm working on need to use sentinel values, >which I'd typically get from limits.h. Can I get away with this? > > U32 aU32 = ULONG_MAX; > while (aU32 == ULONG_MAX) { > /* try to change aU32... > * ... > */ > }
No. You might be on a platform where 'unsigned long' was 64 bits, and so ULONG_MAX was 0xffffffffffffffffL but perl's U32 (for unsigned 32) was Configure-d as unsigned int so could never equal ULONG_MAX. Or if you used UV you might be on a platfrom configured for a 64-bit perl even though "unsigned long" was only 32-bits. > >Is there a "limits.h" analog for XS data types like U32, UV, STRLEN, >etc? No. Instead perl has had Configure find system types which are suitable for each types needs. So if you want sentinels either use system types unsigned long aul = ULONG_MAX; Limit your self to a possible subset of the type const U32 U32_MAX = 0xffffffff; but note that on a 64-bit machine it may be possible that au32 > U32_MAX ! or bool value_set = 0 U32 value = ~0; while (!value_set) { ... value = something; value_set = true; } > >Marvin Humphrey >Rectangular Research >http://www.rectangular.com/