{"id":2566,"date":"2024-05-10T07:23:40","date_gmt":"2024-05-10T07:23:40","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=2566"},"modified":"2024-05-10T07:23:40","modified_gmt":"2024-05-10T07:23:40","slug":"_noreturn-function-specifier-in-c","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/_noreturn-function-specifier-in-c\/","title":{"rendered":"_Noreturn Function Specifier In C"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\" id=\"rank-math-toc\"><p>Table of Contents<\/p><nav><ul><li ><a href=\"#noreturn-function-specifier-in-c\">_Noreturn Function Specifier In C<\/a><\/li><li ><a href=\"#example-1-to-illustrate-how-noreturntype\">Example 1: To illustrate  how_Noreturntype<\/a><\/li><li ><a href=\"#example-2-to-illustrate-the-working-of-a-no-return-statement\">Example 2: To illustrate the working of a No-return statement<\/a><\/li><li ><a href=\"#faq-noreturn-function-specifier-in-c\">FAQ- _Noreturn function specifier in C<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"noreturn-function-specifier-in-c\">_Noreturn Function Specifier In C<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>_Noreturn<\/code> keyword in a function declaration tells the compiler that the function will not return by executing a <code>return<\/code> statement or reaching the end of the function body. If a function is marked with <code>_Noreturn<\/code> does return, the behavior is undefined, and it&#8217;s a good practice for the compiler to provide a diagnostic message if it detects this situation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use the <code>_Noreturn<\/code> specifier multiple times in the same function declaration, and it has the same effect as if it appeared only once.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Typically, you use this specifier through the convenience macro <code>noreturn<\/code>, which is available in the <code>stdnoreturn.h<\/code> header. It helps improve code readability and maintainability when specifying that a function does not return.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>_Noreturn function specifier is deprecated. &#91;&#91;noreturn]] attribute should be used instead.\nThe macro noreturn is also deprecated.<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-1-to-illustrate-how-noreturntype\">Example 1: To illustrate  how_Noreturntype<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/\/ C program to show how _Noreturn type \n\/\/ function behave if it has return statement.\n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n \n\/\/ With return value\n_Noreturn void view()\n{\n    return 10;\n}\nint main(void)\n{\n    printf(\"Ready to begin...\\n\");\n    view();\n \n    printf(\"NOT over till now\\n\");\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Ready to begin...\nAfter that abnormal termination of program.\ncompiler error:&#91;Warning] function declared 'noreturn' has a 'return' statement<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-2-to-illustrate-the-working-of-a-no-return-statement\">Example 2: To illustrate the working of a No-return statement<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\n\/\/ C program to illustrate the working \n\/\/ of _Noreturn type function.\n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n \n\/\/ Nothing to return\n_Noreturn void show()\n{\n    printf(\"BYE BYE\");\n}\nint main(void)\n{\n    printf(\"Ready to begin...\\n\");\n    show();\n \n    printf(\"NOT over till now\\n\");\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Ready to begin...\nBYE BYE<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq-noreturn-function-specifier-in-c\">FAQ- _Noreturn function specifier in C<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1696848383533\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1. What is the Noreturn function specifier in C?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. In C, a function specifier is like a label that tells the compiler how a function should behave. When you use the <code>inline<\/code> function specifier, you&#8217;re suggesting to the compiler that it should replace each call to that function with the actual code inside the function. This can help improve performance by reducing the overhead of function calls.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1696848394873\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2. What are non-returning functions C++?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. A non-value returning function, or void function in C, doesn&#8217;t provide a result. It automatically returns to the caller at the end of the function, and you don&#8217;t need a return statement.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1696848918621\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. Does the Noreturn function return?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. In C, the <code>_Noreturn<\/code> keyword in a function declaration means that the function doesn&#8217;t return via a <code>return<\/code> statement or by reaching the end of its body (though it can return via <code>longjmp<\/code>). If a function is marked as <code>_Noreturn<\/code> does return under normal circumstances, the behavior is undefined.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>_Noreturn Function Specifier In C The _Noreturn keyword in a function declaration tells the compiler that the function will not return by executing a return statement or reaching the end of the function body. If a function is marked with _Noreturn does return, the behavior is undefined, and it&#8217;s a good practice for the compiler &#8230; <a title=\"_Noreturn Function Specifier In C\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/_noreturn-function-specifier-in-c\/\" aria-label=\"More on _Noreturn Function Specifier In C\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":2568,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[432],"class_list":["post-2566","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-_noreturn-function-specifier-in-c","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=2566"}],"version-history":[{"count":8,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2566\/revisions"}],"predecessor-version":[{"id":10657,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2566\/revisions\/10657"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/2568"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=2566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=2566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=2566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}