xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_116.c (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: msg_116.c,v 1.4 2021/01/31 11:12:07 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 	return a - b > 0;	/* expect: 116 */
16 }
17 
18 /*
19  * Even though signed char and unsigned char have the same size,
20  * their pointer types are still considered incompatible.
21  *
22  * C99 6.5.5p9
23  */
24 _Bool
25 subtract_character_pointers(signed char *scp, unsigned char *ucp)
26 {
27 	return scp - ucp > 0;	/* expect: 116 */
28 }
29 
30 _Bool
31 subtract_const_pointer(const char *ccp, char *cp)
32 {
33 	return ccp - cp > 0;
34 }
35