diff options
| author | 2022-08-07 06:41:48 +0200 | |
|---|---|---|
| committer | 2022-08-07 06:41:48 +0200 | |
| commit | 27e22daa10040999f6e5bfe47aa2b8b504b40071 (patch) | |
| tree | d6c99539f5e30f1927c5c616ae14d21e5d325313 /bootstrap/test.cff | |
| parent | 4a0b52a8259810ef7838eece5af030158616d5e5 (diff) | |
union init
Diffstat (limited to 'bootstrap/test.cff')
| -rw-r--r-- | bootstrap/test.cff | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/bootstrap/test.cff b/bootstrap/test.cff index e466bba..a000224 100644 --- a/bootstrap/test.cff +++ b/bootstrap/test.cff @@ -1,11 +1,12 @@ import "libc.hff"; import "libc.hff"; + union Val { - x i64, - lo i32, - y f64, + u u32, + f f32, } + enum Color { Red, Green, Blue } @@ -50,9 +51,16 @@ struct Vec2f { fn spanz(cstr *const u8) [#]const u8 { extern fn strlen(s *const u8) usize; - return cstr[0::strlen(cstr)]; + return cstr[0::strlen(cstr) + 1]; } +defmacro transmute(Type, x) [ + (do + union T { from typeof(x), to Type }; + T{x}.to; + ) +] + extern fn main (argc int, argv **u8) int { let colors [3]Color = { :Red, :Green, :Blue } ; @@ -77,6 +85,7 @@ extern fn main (argc int, argv **u8) int { printf("sizeof(is) = %zu\n", sizeof(is)); printf("sizeof *void = %zu\n", sizeof *void); + printf("1.2 -> %#.8x\n", transmute(u32, 1.2f)); return 0; |