본문 바로가기

공부/C언어

(36)
3.[stm32f103][C언어] 구조체 화살표 연산자(포인트 멤버 연산자)-> #include typedef struct{unsigned int a;}test_type; void main(void){test_type *ptr;test_type test_type1;ptr = &test_type1;ptr->a = 5000;printf("%d\r\n",ptr->a); } 결과
3.[stm32f103][C언어] 구조체 포인터 1, test1.c #include "test.h" void main() { test1_s test1; test1.a = 10; test1.b = 20; test1.c = 30; print_test(&test1); } 2. test2.c #include "test.h" void print_test(unsigned int *val) { unsigned int pa, pb, pc; pa = *val; pb = *(val + 1); pc = *(val + 2); printf("%d\n", pa); printf("%d\n", pb); printf("%d\n", pc); } 3. test.h #include typedef struct { unsigned int a; unsigned int b; unsigned i..
2.[stm32f103][C언어] static 프로젝트 파일 : static void 함수 이름(void) 이런게 많이 보이네요~ 그래서 한번 해보았습니다. 같은 함수이름을 쓰고 싶을 때 앞에다가 static 이라고 쓰면 같은 이름의 함수 를 쓸수 있습니다. 위에 그림 처럼 같은 함수를 a.c b.c 의 소스 파일을 만들어 봤습니다.결과는 에러가 나면서 실패하게 되네요~~ 하지만 b.c 에 static을 붙이니 오류가 사라집니다. 그렇지만 static 붙은 함수는 그 페이지에서만 쓸수 있습니다.static void fun1 같은 경우는 b.c 에서만 쓸수 잇다는 거지요~만약에 main.c에서 fun1() 을 쓰면 a.c 것을 쓰게 됩니다.
1.[stm32f103][C언어] 구조체 return 1. HAL 드라이버 는 구조체랑 포인트가 자주 사용합니다. 그래서 하다가 C언어에 대해서도 종종 테스트 겸 글을 올릴 예정입니다. 먼저 USART 하다가 함수 결과를 구조체로 반환 하는 함수가 있어서 C언어로 테스트 해봤습니다. 2. 파일 3. 소스 헤더 #include typedef enum { HAL_OK = 0x00U, HAL_ERROR = 0x01U, HAL_BUSY = 0x02U, HAL_TIMEOUT = 0x03U }HAL_StatusTypeDef; 소스 #include "test.h" HAL_StatusTypeDef test(int i) { if(i==1) return HAL_OK; else if (i == 2) return HAL_ERROR; else if (i == 3) return H..