-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtdefvolpragma.c
87 lines (74 loc) · 1.71 KB
/
tdefvolpragma.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
typedef, volatile, pragma 키워드
https://modoocode.com/103
*/
#include <stdio.h>
/* 전처리기 명령에는 ; 를 붙이지 않는다! */
// #pragma pack(1) <- MS compiler에서만 유용. 기본값 : 4
#ifndef WEIRD_H // <- 이렇게 하면 헤더를 두번 불러도 재정의 오류 안 생김
#define WEIRD_H
typedef struct WEIRD
{
char arr[2];
int i;
}WEIRD;
#endif
// 아니면 위에서 그냥 #pragma once 라고 해도 됨 (MS 컴파일러에서는)
// gcc에서도 되는 듯 https://en.wikipedia.org/wiki/Pragma_once
struct HUMAN
{
int age;
int height;
int weight;
int gender;
};
typedef int CAL_TYPO;
typedef struct HUMAN Human;
int Print_Status(Human human);
typedef struct SENSOR
{
/* 감지 안되면 0, 감지되면 1 이다.*/
int sensor_flag;
int data;
} SENSOR;
int main()
{
CAL_TYPO a = 1;
Human Adam = {31, 182, 75, 0};
Human Eve = {27, 166, 48, 1};
SENSOR SomeSensorFromHardware;
volatile SENSOR *sensor;
sensor = &SomeSensorFromHardware;
printf("%d\n", a);
Print_Status(Adam);
Print_Status(Eve);
while (!(sensor->sensor_flag))
{
} // sensor.sensor_flag의 값이 0에서 1로 변하면
printf("Data : %d\n", sensor->data); // 이걸 실행 with volatile keyword
WEIRD b;
printf("size of b : %d\n", sizeof(b));
}
int Print_Status(Human human)
{
if (human.gender == 0)
{
printf("MALE \n");
}
else
{
printf("FEMALE \n");
}
printf("AGE : %d / Height : %d / Weight : %d \n", human.age, human.height,
human.weight);
if (human.gender == 0 && human.height >= 180)
{
printf("HE IS A WINNER!! \n");
}
else if (human.gender == 0 && human.height < 180)
{
printf("HE IS A LOSER!! \n");
}
printf("------------------------------------------- \n");
return 0;
}