[Cryptography] GCC bug 30475 (was Re: bounded pointers in C)

Anton Titov anton at titov.net
Fri Apr 25 04:03:55 EDT 2014


On 25.04.2014 09:31, Stephan Neuhaus wrote:
> #include <stdint.h>
>
> #if sizeof(ptrdiff_t) == 4
> #  define PTRDIFF_T_MAX INT32_MAX
> #elif sizeof(ptrdiff_t) == 8
> #  define PTRDIFF_T_MAX INT64_MAX
> #else
> #  error Your ptrdiff_t has a weird size
> #endif
You can not use sizeof() in macro. The preprocessor would have to parse 
your structures in order to know sizeof-s and it does not. You can of 
course do:

#define PTRDIFF_T_MAX 
(sizeof(ptrdiff_t)==4?INT32_MAX:sizeof(ptrdiff_t)==8?INT64_MAX:bad_ptrdiff_t_size())

This should be replaced during compilation with a constant. I believe 
that most compilers will not complain about non-existence of 
bad_ptrdiff_t_size(), but
if you are concerned you can always provide declaration only of this 
function, so compiling this on a weird platform without 
bad_ptrdiff_t_size will yield linking
error.

Anton


More information about the cryptography mailing list