728x90
반응형
0. 파일
1. main.c
#include "test.h"
test1_handle test1;
test2_handle test2;
unsigned int main_a[2] = {0};
void main_test_init1(void)
{
test1.a = &main_a[0];
test1.b = 0;
}
void main_test_init2(void)
{
test2.Ins = &test1;
test2.test2_val = 0;
}
void main_test1(test1_handle* user_test1)
{
user_test1->b = *(user_test1->a);
//printf("%d\r\n", *(user_test1->a));
//printf("b=%d\r\n", user_test1->b);
}
void main_test2(test2_handle* user_test1)
{
user_test1->test2_val = user_test1->test2_val + user_test1->Ins->b;
//printf("%d\r\n", user_test1->test2_val);
}
void main(void)
{
main_test_init1();
main_test_init2();
//main_test(&test1);
while (1)
{
main_a[0]++;
main_test1(test2.Ins);
main_test2(&test2);
printf("main_a[0]=%d\r\n", main_a[0]);
printf("test2_val=%d\r\n", test2.test2_val);
printf("test2_val=%d\r\n", test2.test2_val);
Sleep(1000);
}
}
2. test.h
#include <stdio.h>
#include <windows.h>
typedef struct
{
volatile unsigned int *a;
volatile unsigned int b;
}test1_handle;
typedef struct
{
test1_handle *Ins;
int test2_val;
}test2_handle;
3. 결과
728x90
반응형
'공부 > C언어' 카테고리의 다른 글
6.[C언어] 배열 초기화 하기 (0) | 2018.03.09 |
---|---|
[c언어] 포인트 문자열 (0) | 2018.03.09 |
4.[stm32f103][C언어] 포인터 사용하기 (0) | 2017.12.08 |
3.[stm32f103][C언어] 구조체 화살표 연산자(포인트 멤버 연산자)-> (0) | 2017.12.07 |
3.[stm32f103][C언어] 구조체 포인터 (0) | 2017.11.29 |