-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
53 lines (44 loc) · 1.01 KB
/
main.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
/*
02.02.2021
Ozel Veri Yapisi tanimlama
Struct Union yapilarinin ortak kullanimi
*/
#include <stdio.h>
#include <stdlib.h>
#pragma pack(1)
#define VTTYPE_EMPTY 0
#define VTTYPE_BYTE 1
#define VTTYPE_WORD 2
#define VTTYPE_LONG 3
#define VTTYPE_FLOAT 4
typedef struct MYVAR{
unsigned char type;
union {
char chVal;
short shVal;
int iVal;
double dfVal;
};
}MYVAR;
int main()
{
MYVAR tm;
tm.type = VTTYPE_FLOAT;
tm.dfVal = 5343.67;
printf("MYVAR sizeof = %d\n" , sizeof(tm) );
if( tm.type == VTTYPE_EMPTY )
printf("Value is empty!\n");
else
if( tm.type == VTTYPE_BYTE )
printf("BYTE = %X\n" , tm.chVal );
else
if( tm.type == VTTYPE_WORD )
printf("Word = %d\n" , tm.shVal );
else
if( tm.type == VTTYPE_LONG )
printf("Long = %lf\n" , tm.iVal );
else
if( tm.type == VTTYPE_FLOAT )
printf("Float = %lf\n" , tm.dfVal );
return 0;
}