-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
56 lines (40 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
54
55
56
/*
How to Use ARROWS - More elegant solution to Point to a element of the struct
Description:
Demo of How to Use ARROWS!
Please see notes below.
**********************
Output:
Uart Address = 6487568
BaudRate = 9600; ComPort = 0
**********************
Author: microgenios.com.br
Edited by j3
Date Jun, 21/2020
*/
#include <stdio.h>
#include <stdlib.h>
#pragma pack(1)
typedef struct Serial {
unsigned char ComPort; // X B B B
unsigned int BaudRate; // X X X X
}Serial_t;
void CopyStruct(Serial_t * Uart)
{
// First point to Uart, then access the elements inside
//printf("BaudRate = %d; ComPort = %d\n", (*Uart).BaudRate,(*Uart).ComPort );
// Using ARROWS - More elegant solution, right?
printf("BaudRate = %d; ComPort = %d\n", Uart->BaudRate, Uart->ComPort );
}
int main()
{
Serial_t Uart =
{
.BaudRate = 9600,
.ComPort = 0
};
printf("Uart Address = %d\n", &Uart);
CopyStruct( &Uart);
//system("pause");
return 0;
}