C/C
[C] 헤더파일에 구조체 선언하기
2022. 5. 2. 23:12반응형
주의사항 : 구조체 정의 후 마지막에 꼭 세미콜론 찍자
구조체 선언법 (간단한 방법)
typedef struct {
int num;
char name[100];
} person;
int main()
{
person p = {1, "홍길동"};
}
구조체 선언법
오픈소스를 참고하여,
헤더파일에 구조체를 선언하는 방법을 알아보자.
// 이 헤더파일을 중복 include를 방지하기 위해서, #ifndef 이용
#ifndef CHILD_DELETE_H_
#define CHILD_DELETE_H_
// 구조체 선언 시, 필요한 type 선언
typedef struct child_delete_t child_delete_t;
// 연관된 헤더파일 정의
#include <library.h>
// 구조체 실체 정의
struct child_delete_t {
task_t task;
child_sa_t* (*get_child) (child_delete_t *this);
};
// (아래는 필수는 아니다)
// 구조체 생성문 함수 선언
child_delete_t *child_delete_create(ike_sa_t *ike_sa, protocol_id_t protocol,
uint32_t spi, bool expired);
#endif
소스코드 전문
#ifndef CHILD_DELETE_H_
#define CHILD_DELETE_H_
typedef struct child_delete_t child_delete_t;
#include <library.h>
#include <sa/ike_sa.h>
#include <sa/task.h>
#include <sa/child_sa.h>
/**
* Task of type child_delete, delete a CHILD_SA.
*/
struct child_delete_t {
/**
* Implements the task_t interface
*/
task_t task;
/**
* Get the CHILD_SA to delete by this task.
*
* @return child_sa
*/
child_sa_t* (*get_child) (child_delete_t *this);
};
/**
* Create a new child_delete task.
*
* @param ike_sa IKE_SA this task works for
* @param protocol protocol of CHILD_SA to delete, PROTO_NONE as responder
* @param spi inbound SPI of CHILD_SA to delete
* @param expired TRUE if CHILD_SA already expired
* @return child_delete task to handle by the task_manager
*/
child_delete_t *child_delete_create(ike_sa_t *ike_sa, protocol_id_t protocol,
uint32_t spi, bool expired);
#endif /** CHILD_DELETE_H_ @}*/
참고자료
https://github.com/strongswan/strongswan/blob/master/src/libcharon/sa/ikev2/tasks/child_delete.h
반응형
'C > C' 카테고리의 다른 글
[C] typedef 사용 예 (0) | 2022.05.30 |
---|---|
[C] (작성중) int8_t 에 대해서 알아보자 (stdint.h ) (0) | 2022.05.30 |
[C] shm_open (0) | 2022.04.22 |
구조체와 공용체 (Struct와 Union)에 대한 고찰 (2) | 2022.02.23 |
[C] Error 상수 error.h (0) | 2021.06.08 |