#define MAXBRAGGPEAKS 10It is also wise not to choose too simple names because they are likely to conflict with already defined ones. Also, one should include at least the name of the package for which they are defined, e.g.:
#define TRP_BRAGGMAX 64is preferrable to just
#define MAX 64
long lVar; int iVar; float rVar; double dVar; char cVar; struct sVar { ... }; long *plVar; int *piVar; float *prVar; double *pdVar; char *pcVar; struct sVar *psVar; void *pvVar;Never use 1-char variable names, e.g. i,j,k for loops. It is very hard to find them with automatic search procedures. Use e.g. ii, jj, kk instead.
... #include "trp.h" int TRPxyz( ... ) { int iRC = ERRTRP_SYS; /* common error code */ ... if ( ( pv = calloc(...) ) == NULL ) { /* allocation failed */ iRC = ERRTRP_SYS; goto gError; } ... iRC = 0; gError:; return(iRC); }
int
stays at 4 bytes,
long
now uses 8 bytes,
and pointers are also 8 bytes to allow for the 64bit address space.
Floating point data/operations should not be affected,
at least theoretically, since they should follow the IEEE standard.
I've seen differences between 32 and 64 bit mode in numerical results,
though, in particular on Linux/x86.
long
to int
if 4 bytes are sufficient.
size_t
(unsigned) or ssize_t
(signed).
These translate to either 4 or 8 byte integers,
depending on whether compilation is for 32 or 64 bits.
Almost all library functions, for example, take size_t
parameters so they can be used for either "bitness".
[s]size_t
might also be necessary for loop variables
addressing large arrays with element numbers exceeding 2**32-1.
int32_t /* signed 32 bits */ uint32_t /* unsigned 32 bits */ int64_t /* signed 64 bits */ uint64_t /* unsigned 64 bits */
printf()
and friends.
printf("%*.*s\n", nn, nn, pcStr );the length counter
nn
must be of int
type
in 64bit mode, in 32bit it could be either int
or long
.
%l
).
In 32bit mode they refer to a 4-byte data type, in 64bit mode
to an 8-byte data type. In 32bit mode %ll
assumes 8-byte.
double dd; int ii; long ll; if ( sizeof(long) == 8 ) fprintf( stderr, "%d %d %ld %G %lX\n", __LINE__, ii, ll, dvz[0], *( (uint64_t *) (&dd)) ); else fprintf( stderr, "%d %d %ld %G %llX\n", __LINE__, ii, ll, dvz[0], *( (uint64_t *) (&dd)) );