From c6c8d4eb53a4092aa076506140d765b628008264 Mon Sep 17 00:00:00 2001 From: neingeist Date: Thu, 24 Apr 2014 12:11:20 +0200 Subject: [PATCH] add a small union example --- .gitignore | 1 + Makefile | 2 +- unions.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 unions.c diff --git a/.gitignore b/.gitignore index c2ab9bb..072cf83 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ hello-openmp mandelbrot-openmp positional-format-strings uiowa-threads-my-example +unions diff --git a/Makefile b/Makefile index 1ef5278..bb54214 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ TARGETS=approximate-pi linked-list mandelbrot threads circular-buffer structs \ uiowa-threads-example uiowa-threads-my-example \ mtrace-test av-variance undefined-behaviour \ multibrot-openmp hello-openmp mandelbrot-openmp \ - positional-format-strings + positional-format-strings unions EXTRAS=mandelbrot.bmp multibrot.png test-inline-assembly.s \ mtrace-test.trace mtrace-test.txt multibrot-openmp.png VERYEXTRAS=cppcheck.txt macros.txt tags diff --git a/unions.c b/unions.c new file mode 100644 index 0000000..73a8d00 --- /dev/null +++ b/unions.c @@ -0,0 +1,14 @@ +#include + +union u_tag { + int ival; + float fval; + char *sval; +} u; + +int main() { + u.ival = 12; + printf("%f\n", u.fval); + u.fval = 0.01; + printf("%d\n", u.ival); +}