Advertisement
RicardasSim

union c

Sep 23rd, 2018
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. //-std=c99
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #include <stdint.h>
  6.  
  7. int main (int argc, char **argv)
  8. {
  9.  
  10. //from VulkanSDK
  11. typedef union VkClearColorValue {
  12.     float       float32[4];
  13.     int32_t     int32[4];
  14.     uint32_t    uint32[4];
  15. } VkClearColorValue;
  16.  
  17. typedef struct VkClearDepthStencilValue {
  18.     float       depth;
  19.     uint32_t    stencil;
  20. } VkClearDepthStencilValue;
  21.  
  22. typedef union VkClearValue {
  23.     VkClearColorValue           color;
  24.     VkClearDepthStencilValue    depthStencil;
  25. } VkClearValue;
  26.  
  27.  
  28.  
  29.     VkClearValue test1;
  30.     VkClearValue test2;
  31.  
  32.     VkClearColorValue vcv;
  33.     VkClearDepthStencilValue cdsv;
  34.  
  35.     vcv.float32[0]=0.1f;
  36.     vcv.float32[1]=0.2f;
  37.     vcv.float32[2]=0.3f;
  38.     vcv.float32[3]=0.4f;
  39.  
  40.     printf("vcv (0): %f\n",vcv.float32[0]);    
  41.     printf("vcv (1): %f\n",vcv.float32[1]);
  42.     printf("vcv (2): %f\n",vcv.float32[2]);
  43.     printf("vcv (3): %f\n\n",vcv.float32[3]);
  44.  
  45.     cdsv.depth=0.5f;
  46.     cdsv.stencil=1;
  47.  
  48.     printf("cdsv (0): %f\n",cdsv.depth);       
  49.     printf("cdsv (1): %d\n\n",cdsv.stencil);
  50.    
  51.    
  52.     test1.color = vcv;
  53.    
  54.     test2.depthStencil = cdsv;
  55.    
  56.    
  57.     printf("test1 (0): %f\n",test1.color.float32[0]);      
  58.     printf("test1 (1): %f\n",test1.color.float32[1]);
  59.     printf("test1 (2): %f\n",test1.color.float32[2]);
  60.     printf("test1 (3): %f\n\n",test1.color.float32[3]);
  61.        
  62.     printf("test2 (0): %f\n",test2.depthStencil.depth);    
  63.     printf("test2 (1): %d\n",test2.depthStencil.stencil);  
  64.    
  65.     //wrong code
  66.     //test1.color = vcv;
  67.     //test1.depthStencil = cdsv;
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement