본문 바로가기

C21

SWIG 라이브러리 00 개요To help build extension modules, SWIG is packaged with a library of support files that you can include in your own interfaces. These files often define new SWIG directives or provide utility functions that can be used to access parts of the standard C and C++ libraries. This chapter provides a reference to the current set of supported library files. Compatibility NOTE: Older versions of SWI.. 2024. 6. 24.
Local vs Global Variable (지역 vs 전역 + static 변수) 00 개요목적: C 언어를 공부하는데 지역 변수, 전역 변수 용어들이 등장해서 정리하고자 함C 언어에서 변수는 크게 지역, 전역, 그리고 static 변수로 나뉨각 변수의 종류는 변수의 범위와 수명 등에서 차이가 있음 01 지역 변수 (Local Variable)1. 정의특정 블록 { }에서 선언된 변수, 블록 내에서만 사용 가능보통 함수 내에서 사용됨지역 변수는 함수가 호출되면 생성되며 함수 종료 시 소멸됨 (메모리 stack영역에 저장되기 때문)2. 예시#include void test() { int num = 10; // 지역 변수 num 선언 printf("%d\n", num);}int main() { test(); printf("%d\n", num); return 0;.. 2024. 6. 24.
extern와 static (키워드) 00 개요C 언어 파일 및 SWIG 인터페이스 파일에서 등장해서 정리하고자 함01 extern 키워드란1. 정의 'external' '외부적인'어느 한 파일에서 다른 파일에 정의된(defined) 변수/함수(variable or function)을 참조할 때 사용즉, 다른 파일에 있는 전역 함수를 참조하는 것1) Declaration vs Definition (선언과 정의)참조: 2024.06.24 - [C] - Declaration vs Definition (선언과 정의)  Declaration: A declaration simply informs the program that a variable/function exists somewhere within the program, providing inf.. 2024. 6. 24.
Declaration vs Definition (선언과 정의) 00 개요c 언어를 공부하는데 변수를 선언하느냐 정의하느냐 해서 이에 관해 정리해보고자 함01 Declaration vs Definition (선언과 정의)1. 각 용어의 정의Declaration: A declaration simply informs the program that a variable/function exists somewhere within the program, providing info about its type (for variables) and its arguments and return type (for functions). Declarations do not allocate memory. Definition: A definition encompasses everything th.. 2024. 6. 24.
SWIG (C/C++와 다른 언어 연결하는 도구) 00 개요목적: SWIG가 뭔지 정리하기 위함내용: SWIG의 정의, SWIG의 기본적인 작업, input file들의 구조, 표준 ANSI C declaration을 어떻게 처리하는지SWIG 공식 문서의 "5 SWIG Basics"를 거의 그대로 적음01 SWIG란1. 정의'Simplified Wrapper and Interface Generator'C/C++ 언어로 된 Declaration들을 다른 언어로 된 wrapper와 interface를 생성하는 무료 도구SWIG is a free software development tool (an interface compiler) that takes C/C++ declarations and creates the wrappers needed to acce.. 2024. 6. 21.
typedef (자료형 별칭 부여 키워드) 00 개요typedef가 뭔지 알아보고자 함01 typedef란1. 정의'type' 자료 'define' 정의하다즉, 기존 자료형 (type)에 새롭게 별칭을 부여하는 키워드(keyword)2. 문법typedef 기존type 별칭;02 typedef 사용1. 구조체에 별칭 부여NOTE: 관례상 구조체이름(tag) 앞에 _(underslash) 또는 tag_ 또는 tag를 붙여줌1) 방법 1struct _구조체이름 { 자료형 멤버이름; 자료형 멤버이름; ...};typedef struct _구조체이름 구조체별칭;예시#include struct _data { int data1; char * data2; // 또는 char data2[20];};typedef struct _data .. 2024. 6. 21.
strcpy() strcpy_s() (문자열 복사 함수) 00 개요목적: 문자열을 복사하는 함수인 strcpy()와 strcpy_s()에 대해 정리하고자 함01 strcpy() 함수란1. 정의'string copy''문자열을 복사한다'어떤 변수(메모리) 또는 문자열 상수에 저장되어 있는 문자열을 다른 변수(메모리)에 복사 시 사용됨반환값: char * 형식의 주소NOTE: 복사할 원본 문자열은 반드시 끝에 NULL 문자가 포함되어 있어야 함2. 문법 (함수의 원형)strcpy 함수의 원형은 string.h에 다음과 같이 선언되어있음char *strcpy(char *strDestination, const char *strSource);strcpy() 함수는 2개의 parameter를 사용하여 2번째 인자인 strSource 포인터가 가리키는 메모리에 저장된 문자.. 2024. 6. 21.
struct (구조체) 00 개요목적: C 언어에서 사용되는 구조체 이해하기자료형기초 자료형 Primary파생 자료형Derived사용자-정의 자료형User-Definedint / unsigned intshort / unsigned shortlong / unsigned longchar / unsigned charfloatdoublelong doublevoid...function (함수)array (배열)pointer (포인터)reference (참조)classstruct (구조체)union (공용체) typedefenum (열거형)동일한 종류의 데이터를 하나로 묶을 경우 배열을 사용했지만 (int numbers[5] = { 2, 5, 3, 7, 1 };), 다른 종류의 데이터(int, double, char, etc.)를 하나로.. 2024. 6. 21.
sizeof() 연산자 01 sizeof() 연산자1. 정의피연산자(연산자의 대상, operand)의 메모리의 크기를 바이트(Byte) 단위로 계산하여 반환반환 타입: size_t포인터, 데이터 타입, 구조체, 공용체 모두 사용 가능// 데이터 타입 피연산자size_t size_char = sizeof(char); // 1size_t size_int = sizeof(int); // 4size_t size_float = sizeof(float); // 4size_t size_double = sizeof(double); // 8// 표현식 피연산자int a = 10;double d = 10.24;size_t size = sizeof(a + d); // 8sizeof(a+d)가 8인 이유는 a + d 연산 처리 시 타입이 큰 dou.. 2024. 6. 21.