1 1.2 rillig /* $NetBSD: expr_cast.c,v 1.2 2021/08/03 18:38:02 rillig Exp $ */ 2 1.1 rillig # 3 "expr_cast.c" 3 1.1 rillig 4 1.1 rillig /* 5 1.1 rillig * Tests for value conversion using a cast-expression. 6 1.1 rillig * 7 1.1 rillig * K&R C does not mention any restrictions on the target type. 8 1.1 rillig * C90 requires both the source type and the target type to be scalar. 9 1.2 rillig * 10 1.2 rillig * GCC allows casting to a struct type but there is no documentation about 11 1.2 rillig * it at https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html. See 12 1.2 rillig * c-typeck.c, function build_c_cast, RECORD_OR_UNION_TYPE_P. 13 1.1 rillig */ 14 1.1 rillig 15 1.2 rillig /* lint1-flags: -Sw */ 16 1.2 rillig 17 1.1 rillig struct S { 18 1.1 rillig int member; 19 1.1 rillig }; 20 1.1 rillig 21 1.1 rillig struct S 22 1.1 rillig cast(void) 23 1.1 rillig { 24 1.1 rillig struct S { 25 1.1 rillig double incompatible; 26 1.1 rillig } local = { 27 1.1 rillig 0.0 28 1.1 rillig }; 29 1.1 rillig 30 1.2 rillig /* expect+2: error: invalid cast from 'struct S' to 'struct S' [147] */ 31 1.2 rillig /* expect+1: warning: function cast expects to return value [214] */ 32 1.1 rillig return (struct S)local; 33 1.1 rillig } 34