libtomcrypt
libtomcrypt copied to clipboard
Polish API `unsigned long` vs. `size_t` for sizes/lengths
As mentioned in #174 and #173 we should consider switching from unsigned long
to size_t
when passing the length or size of something.
@rofl0r said:
also: in C the proper type for sizes is size_t, not unsigned long. (usually it's the same, but some odd platforms like windows have a 32bit long on 64bit).
and @rofl0r a bit later:
using size_t does not necessarily mean including stdint.h. since you're a fan of ifdef hacks over configure tests you could hardcode a list of CPP defines which define HAVE_STDINT_H and only use it there, for the other platforms fall back to typedefing it to unsigned long, or unsigned long long on windows64 bit.
i thought about this some more and i came to the conclusion that in order to keep future problems to a mininum it's probably not a good idea to make a manual typedef to size_t on platforms that currently do not provide stdint.h, because future version may actually have stdint.h and pull in the header implicitly through inclusion of another header, so the typedef will be problematical. so if you want to go that route it's preferable to have a custom type, for example ltc_size, which is typedef'd to unsigned long or size_t, depending on the platform.
To my surprise even pretty old MS compilers are able to handle size_t
.
TBH I'm not aware of any platform that I used lately which doesn't have stdint.h
so I'm against introducing something like ltc_size
or even worse some "macro-own-typedef-magic"^TM. I'd rather make it up to the integrator of the library to provide a stdint.h
himself with the appropriate typedefs if there's none available ootb.
btw according to man 0p stddef.h
, stddef.h is the proper header to include to get this type.
stddef.h is the proper header to include to get this type
mea culpa, you're right! no more typing for me today