Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Inline recursive functions

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading