add a small union example

master
neingeist 11 years ago
parent 90e69a4c54
commit c6c8d4eb53

1
.gitignore vendored

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

@ -11,7 +11,7 @@ TARGETS=approximate-pi linked-list mandelbrot threads circular-buffer structs \
uiowa-threads-example uiowa-threads-my-example \ uiowa-threads-example uiowa-threads-my-example \
mtrace-test av-variance undefined-behaviour \ mtrace-test av-variance undefined-behaviour \
multibrot-openmp hello-openmp mandelbrot-openmp \ multibrot-openmp hello-openmp mandelbrot-openmp \
positional-format-strings positional-format-strings unions
EXTRAS=mandelbrot.bmp multibrot.png test-inline-assembly.s \ EXTRAS=mandelbrot.bmp multibrot.png test-inline-assembly.s \
mtrace-test.trace mtrace-test.txt multibrot-openmp.png mtrace-test.trace mtrace-test.txt multibrot-openmp.png
VERYEXTRAS=cppcheck.txt macros.txt tags VERYEXTRAS=cppcheck.txt macros.txt tags

@ -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);
}
Loading…
Cancel
Save