C언어에서 여러분들이 만든 함수의 리턴 값이 없다는 것을 명시해 주고 싶습니다.
void와는 다른 형태로 표준 라이브러리 중 abort()나 exit() 같은 함수들입니다.
그때 사용하는 방법이 noreturn 입니다.
noreturn
abort
and exit
, cannot return. GCC knows this automatically. Some programs define their own functions that never return. You can declare them noreturn
to tell the compiler this fact. For example, void fatal () __attribute__ ((noreturn));
void
fatal (...)
{
... /* Print error message. */ ...
exit (1);
}
The noreturn
keyword tells the compiler to assume that fatal
cannot return. It can then optimize without regard to what would happen if fatal
ever did return. This makes slightly better code. More importantly, it helps avoid spurious warnings of uninitialized variables.
Do not assume that registers saved by the calling function are restored before calling the noreturn
function.
It does not make sense for a noreturn
function to have a return type other than void
.
The attribute noreturn
is not implemented in GCC versions earlier than 2.5. An alternative way to declare that a function does not return, which works in the current version and in some older versions, is as follows:
typedef void voidfn ();
volatile voidfn fatal;
'Language > C,C++' 카테고리의 다른 글
C언어 try-catch 흉내내기 (0) | 2018.03.19 |
---|---|
[C언어] 실수형 MAX, MIN 값 (0) | 2017.11.05 |
[C언어] Header File 한번만 포함하기. (0) | 2015.09.13 |
[C언어] limits.h (0) | 2014.10.20 |
텍스트 파일 한줄씩 입력받기. (0) | 2014.05.19 |