add a small union example
This commit is contained in:
		
							parent
							
								
									90e69a4c54
								
							
						
					
					
						commit
						c6c8d4eb53
					
				
					 3 changed files with 16 additions and 1 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
										
									
									
									
								
							| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										14
									
								
								unions.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								unions.c
									
										
									
									
									
										Normal 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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue