This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.
Released under the GNU General Public License.
ptrdiff_t
Prototype
#include <stddef.h>
typedef implementation-defined ptrdiff_t;
Description
The ptrdiff_t
type is the signed integral type of the
result of subtracting two pointers.
Example
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
/*
* Apply the function `func' to the sequence of `T' objects,
* starting from `begin', terminating before `end', excluded.
*/
#define APPLY(T, begin, end, func) \
do { \
T *p = begin; \
ptrdiff_t d = end - begin; \
if (d == 0) \
break; \
else if (d > 0) \
while (p < end) \
func(*p++); \
else /* d < 0 */ \
while (p > end) \
func(*--p); \
} while (0)
int main(void)
{
char s[] = "Hello world";
APPLY(char, &s[0], &s[11], putchar);
putchar('\n');
APPLY(char, &s[11], &s[0], putchar);
putchar('\n');
return EXIT_SUCCESS;
}
References
ISO C 9899:1990 7.1.6