[Cryptography] bounded pointers in C

Patrick Chkoreff patrick at rayservers.net
Sun Apr 20 09:12:09 EDT 2014


Bear wrote, On 04/18/2014 06:58 PM:

> C++11 and later mandate the existence of a type "intptr_t" which is
> defined as an integer large enough to hold the value of any pointer.  
> You get access to it if you include the stdint library.
> 
> In a system with fat pointers intptr_t may be larger than long long
> int. 

According to the C Language Reference Manual, it is guaranteed that a
"long" (a.k.a "long int") is large enough to hold any pointer value.

I have to infer that by reading between the lines though.  Here is my
reasoning:

~@@@@
The standard explicitly says:

  long ints are large enough to hold pointers in -n32 and -o32 mode.
  Both are 32 bits wide.

  long ints are large enough to hold pointers in -64 mode.
  Both are 64 bits wide.

(C Language Reference Manual, document 007-0701-150, Appendix A, Section
F.3.7 "Arrays and Pointers")

Assuming there are no other modes, I conclude that long ints are large
enough to hold pointers, period.

As further evidence, the section titled "Integer and Floating Point
Types" has a table of Storage Class Sizes that lists the size in bits
for the various types in all three modes -o32, -n32, and -64.  In all
modes the size of a long equals the size of a pointer.
@@@@


The assumption of course is that the three modes they mention, -n32,
-o32, and -64, are the only modes that exist.

If I ever cross-compile my code to a CDC 3600 from 1979 with a 60-bit
word, I may have to rethink this, but I bet both longs and pointers
would be 60 bits there too.


-- Patrick



More information about the cryptography mailing list