1 /* $NetBSD: d_c99_compound_literal_comma.c,v 1.3 2021/03/20 11:24:49 rillig Exp $ */ 2 # 3 "d_c99_compound_literal_comma.c" 3 4 /*- 5 * Ensure that compound literals can be parsed. 6 * 7 * C99 6.5.2 "Postfix operators" for the syntax. 8 * C99 6.5.2.5 "Compound literals" for the semantics. 9 */ 10 11 struct point { 12 int x; 13 int y; 14 }; 15 16 struct point 17 point_abs(struct point point) 18 { 19 /* No designators, no trailing comma. */ 20 if (point.x >= 0 && point.y >= 0) 21 return (struct point){ point.x, point.y }; 22 23 /* Designators, no trailing comma. */ 24 if (point.x >= 0) 25 return (struct point){ .x = point.x, .y = -point.y }; 26 27 /* No designators, trailing comma. */ 28 if (point.y >= 0) 29 return (struct point){ point.x, point.y, }; 30 31 /* Designators, trailing comma. */ 32 return (struct point){ .x = point.x, .y = -point.y, }; 33 } 34