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); +}