Single source INTEGER declarations for 32-bit and 64-bit builds

Single source INTEGER declarations for 32-bit and 64-bit builds

If I want to maintain a single set of source code for 32-bit and 64-bit builds, what is the best way to declare INTEGER variables that are automatically 4 bytes for 32-bit and 8 bytes for 64-bit? Should I use:

INTEGER (INT_PTR) MyInt
or
INTEGER (KIND=INT_PTR_KIND()) MyInt

or are they the same? Is there a better way to declare MyInt?

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I like to use C_INTPTR_T from ISO_C_BINDING.  It won't trigger standard conformance warnings.

This assumes that a pointer in C has the relevant bitness.  In the segmented memory days things weren't always so straight forward.

Leave a Comment

Please sign in to add a comment. Not a member? Join today