1 /* $NetBSD: msg_116.c,v 1.5 2022/06/16 16:58:36 rillig Exp $ */ 2 # 3 "msg_116.c" 3 4 // Test for message: illegal pointer subtraction [116] 5 6 /* 7 * Subtracting an int pointer from a double pointer does not make sense. 8 * The result cannot be reasonably defined since it is "the difference of 9 * the subscripts of the two array elements" (C99 6.5.5p9), and these two 10 * pointers cannot point to the same array. 11 */ 12 _Bool 13 example(int *a, double *b) 14 { 15 /* expect+1: error: illegal pointer subtraction [116] */ 16 return a - b > 0; 17 } 18 19 /* 20 * Even though signed char and unsigned char have the same size, 21 * their pointer types are still considered incompatible. 22 * 23 * C99 6.5.5p9 24 */ 25 _Bool 26 subtract_character_pointers(signed char *scp, unsigned char *ucp) 27 { 28 /* expect+1: error: illegal pointer subtraction [116] */ 29 return scp - ucp > 0; 30 } 31 32 _Bool 33 subtract_const_pointer(const char *ccp, char *cp) 34 { 35 return ccp - cp > 0; 36 } 37