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