RicardasSim icon

struct

RicardasSim | PRO | 04/29/20 08:33:57 AM UTC | 0 ⭐ | 1010 👁️ | Never ⏰ | []
C |

1.21 KB

|

None

|

0 👍

/

0 👎

//-std=c99 -Wall -Wextra -Wpedantic -Wshadow
 
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
 
typedef struct{
    int *p1;
    size_t size;
} TestStruct;
 
TestStruct ts1;
 
int main()
{
    TestStruct ts2;
 
    printf("%s\n", ts1.p1 ? "NOT NULL" : "NULL");
    printf("%p\n", (void*) ts1.p1);
    printf("%zu\n", ts1.size);
 
    printf("%s\n", ts2.p1 ? "NOT NULL" : "NULL");
    printf("%p\n", (void*) ts2.p1);
    printf("%zu\n", ts2.size);
 
    ts2.p1 = NULL;
    ts2.size = 0;
 
    printf("%s\n", ts2.p1 ? "NOT NULL" : "NULL");
    printf("%p\n", (void*) ts2.p1);
    printf("%zu\n", ts2.size);    
 
    return 0;
}
 
/*
 
main.c:23:23: warning: ‘ts2.p1’ is used uninitialized in this function [-Wuninitialized]
     printf("%s\n", ts2.p1 ? "NOT NULL" : "NULL");
                    ~~~^~~
main.c:24:31: warning: ‘ts2.p1’ is used uninitialized in this function [-Wuninitialized]
     printf("%p\n", (void*) ts2.p1);
                            ~~~^~~
main.c:25:5: warning: ‘ts2.size’ is used uninitialized in this function [-Wuninitialized]
     printf("%zu\n", ts2.size);
 
output:
 
NULL
(nil)
0
NOT NULL
0x7ffffcca5ea0
0
NULL
(nil)
0
 
 
*/

Comments