I thought that calling a inline
function inside of itself wouldn't be allowed because it would lead to something like infinite source code when the function's invokations get replaced with its body(if that happends). But, when I test is that allowed, I get a Segmentation fault
. Example code:
static inline void a(void){
a();
}
int main(void){
a();
return 0;
}
I want to ask why is not a compile-error generated in the first place, and also why this leads to a Segmentation fault
. Thanks for reaching out.
CodePudding user response:
As @HolyBlackCat mentioned - inline is only a hint for a compiler. Compiler ignores it in a lot of cases.
As for your test - your recursive code causes a crash because of stack overflow error - every function call reserves a memory block on the stack and your program runs out of memory.