expr_promote_trad.c revision 1.5
11.5Srillig/* $NetBSD: expr_promote_trad.c,v 1.5 2024/11/05 04:53:28 rillig Exp $ */ 21.1Srillig# 3 "expr_promote_trad.c" 31.1Srillig 41.1Srillig/* 51.1Srillig * Test arithmetic promotions in traditional C. 61.1Srillig */ 71.1Srillig 81.4Srillig/* lint1-flags: -tw -X 351 */ 91.1Srillig 101.1Srilligsink(); 111.1Srillig 121.1Srilligstruct arithmetic_types { 131.1Srillig /* _Bool is not available in traditional C */ 141.1Srillig char plain_char; 151.1Srillig /* signed char is not available in traditional C */ 161.1Srillig unsigned char unsigned_char; 171.1Srillig short signed_short; 181.1Srillig unsigned short unsigned_short; 191.1Srillig int signed_int; 201.1Srillig unsigned int unsigned_int; 211.1Srillig long signed_long; 221.1Srillig unsigned long unsigned_long; 231.1Srillig /* (unsigned) long long is not available in traditional C */ 241.1Srillig /* __int128_t is not available in traditional C */ 251.1Srillig /* __uint128_t is not available in traditional C */ 261.1Srillig float single_floating; 271.1Srillig double double_floating; 281.1Srillig /* long double is not available in traditional C */ 291.1Srillig /* _Complex is not available in traditional C */ 301.2Srillig enum { 311.2Srillig E 321.2Srillig } enumerator; 331.1Srillig}; 341.1Srillig 351.1Srilligcaller(arg) 361.1Srillig struct arithmetic_types *arg; 371.1Srillig{ 381.3Srillig /* See expr_promote_trad.exp-ln for the resulting types. */ 391.1Srillig sink("", 401.1Srillig arg->plain_char, /* gets promoted to 'int' */ 411.1Srillig arg->unsigned_char, /* gets promoted to 'unsigned int' */ 421.1Srillig arg->signed_short, /* gets promoted to 'int' */ 431.1Srillig arg->unsigned_short, /* gets promoted to 'unsigned int' */ 441.1Srillig arg->signed_int, 451.1Srillig arg->unsigned_int, 461.1Srillig arg->signed_long, 471.1Srillig arg->unsigned_long, 481.1Srillig arg->single_floating, /* gets promoted to 'double' */ 491.2Srillig arg->double_floating, 501.5Srillig arg->enumerator); /* should get promoted to 'int' */ 511.1Srillig} 521.2Srillig 531.2Srillig/* 541.2Srillig * XXX: Enumerations may need be promoted to 'int', at least C99 6.3.1.1p2 551.2Srillig * suggests that: "If an int can represent ...". 561.2Srillig */ 57