Language/C
[따배씨] 16.11 inline 함수
migrationArc
2021. 9. 7. 14:58
따배씨 - 따라하며 배우는 C언어
16강 전처리기와 라이브러리
16.11 inline 함수
- 작은 함수가 반복하여 사용 될 때, 실행 속도를 높일 수 있는 방법
#include <stdio.h>
/*
Function call has overhead
- set up the call, pass arguments, jump to the function code, end return.
inline function spectifier (함수 특성 지정자)
- suggets inline replacements. (제안을 함)
- function call overhead 가 없어짐
Inline functions should be short.
A function with internal linkage can be made inline.
You can't take its address. -> 함수의 내용을 복사 붙여넣기 처럼 동작하기 때문
*/
inline static int foo()
// internal linkage
{
return 5;
}
int main()
{
int ret;
// inline function call
ret = foo();
printf("Output is : %d\n", ret);
return 0;
}
* ```c
inline static int foo()
// internal linkage
{
return 5;
}
- gcc 나 clang 의 경우는 static 으로 선언하여 internal linkage 처리를 해주어야함
- 함수의 기본 선언은 external 이기 때문
- Compiler 가 자동으로 inline 으로 compile 하거나, function call 로 compile 하기도 함
- inline 은 주로 header 정의하여 사용
이 글의 모든 사진과 내용의 출처는 홍정모 교수님께 있음을 알려드립니다.
http://blog.naver.com/atelierjpro
실리콘 밸리의 프로그래머 : 네이버 블로그
안녕하세요! 홍정모 블로그에 오신 것을 환영합니다. 주로 프로그래밍 관련 메모 용도로 사용합니다. 강의 수강하시는 분들은 홍정모 연구소 카페로 오세요.
blog.naver.com
http://www.inflearn.com/course/following-c
홍정모의 따라하며 배우는 C언어 - 인프런 | 강의
'따배씨++'의 성원에 힘입어 새롭게 개발된 C 언어로 시작하는 프로그래밍 입문 강의입니다. '따배씨'와 함께 프로그래밍 인생을 업그레이드 해보세요., 따라하며 배우는 C언어 '따배씨++'의 성원
www.inflearn.com