1 /* $NetBSD: platform_ilp32_long.c,v 1.4 2023/07/08 15:26:25 rillig Exp $ */ 2 # 3 "platform_ilp32_long.c" 3 4 /* 5 * Test features that only apply to platforms that have 32-bit int, long and 6 * pointer types and where size_t is unsigned long, not unsigned int. 7 * 8 * On these platforms, in portable mode (-p), the type 'int' is in some cases 9 * assumed to be only 24 bits wide, in order to detect conversions from 10 * 'long' (or more probably 'size_t') to 'int', which can lose accuracy. 11 */ 12 13 /* lint1-only-if: ilp32 long */ 14 /* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */ 15 16 int s32; 17 unsigned int u32; 18 long sl32; 19 unsigned long ul32; 20 21 void 22 convert_between_int_and_long(void) 23 { 24 /* 25 * The '-p' option enables checks that apply independently of the 26 * current platform, assuming that 'long' is always wider than 'int'. 27 * This assumption, when applied on its own, leads to wrong warnings 28 * that a 32-bit 'long' may lose accuracy when converted to a 32-bit 29 * 'int'. 30 * 31 * To avoid these, take a look at the actually possible values of the 32 * right-hand side, and if they fit in the left-hand side, don't warn. 33 */ 34 s32 = sl32; 35 sl32 = s32; 36 u32 = ul32; 37 ul32 = u32; 38 } 39