RicardasSim

struct

Apr 29th, 2020
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. //-std=c99 -Wall -Wextra -Wpedantic -Wshadow
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <stdint.h>
  6. #include <stdbool.h>
  7.  
  8. typedef struct{
  9.     int *p1;
  10.     size_t size;
  11. } TestStruct;
  12.  
  13. TestStruct ts1;
  14.  
  15. int main()
  16. {
  17.     TestStruct ts2;
  18.  
  19.     printf("%s\n", ts1.p1 ? "NOT NULL" : "NULL");
  20.     printf("%p\n", (void*) ts1.p1);
  21.     printf("%zu\n", ts1.size);
  22.  
  23.     printf("%s\n", ts2.p1 ? "NOT NULL" : "NULL");
  24.     printf("%p\n", (void*) ts2.p1);
  25.     printf("%zu\n", ts2.size);
  26.  
  27.     ts2.p1 = NULL;
  28.     ts2.size = 0;
  29.  
  30.     printf("%s\n", ts2.p1 ? "NOT NULL" : "NULL");
  31.     printf("%p\n", (void*) ts2.p1);
  32.     printf("%zu\n", ts2.size);    
  33.  
  34.     return 0;
  35. }
  36.  
  37. /*
  38.  
  39. main.c:23:23: warning: ‘ts2.p1’ is used uninitialized in this function [-Wuninitialized]
  40.      printf("%s\n", ts2.p1 ? "NOT NULL" : "NULL");
  41.                     ~~~^~~
  42. main.c:24:31: warning: ‘ts2.p1’ is used uninitialized in this function [-Wuninitialized]
  43.      printf("%p\n", (void*) ts2.p1);
  44.                             ~~~^~~
  45. main.c:25:5: warning: ‘ts2.size’ is used uninitialized in this function [-Wuninitialized]
  46.      printf("%zu\n", ts2.size);
  47.  
  48. output:
  49.  
  50. NULL
  51. (nil)
  52. 0
  53. NOT NULL
  54. 0x7ffffcca5ea0
  55. 0
  56. NULL
  57. (nil)
  58. 0
  59.  
  60.  
  61. */
Advertisement
Add Comment
Please, Sign In to add comment