add a small union example

This commit is contained in:
neingeist 2014-04-24 12:11:20 +02:00
parent 90e69a4c54
commit c6c8d4eb53
3 changed files with 16 additions and 1 deletions

1
.gitignore vendored
View file

@ -34,3 +34,4 @@ hello-openmp
mandelbrot-openmp
positional-format-strings
uiowa-threads-my-example
unions

View file

@ -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

14
unions.c Normal file
View file

@ -0,0 +1,14 @@
#include <stdio.h>
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);
}