{"id":679,"date":"2022-08-30T15:05:22","date_gmt":"2022-08-30T15:05:22","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/why-does-the-compiler-warn-about-and-ignore-the-call-to-my-function-strlen-closed-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:05:22","modified_gmt":"2022-08-30T15:05:22","slug":"why-does-the-compiler-warn-about-and-ignore-the-call-to-my-function-strlen-closed-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/why-does-the-compiler-warn-about-and-ignore-the-call-to-my-function-strlen-closed-collection-of-common-programming-errors\/","title":{"rendered":"Why does the compiler warn about and ignore the call to my function strlen? [closed]-Collection of common programming errors"},"content":{"rendered":"<p>It is perfectly legal to ignore the return value of a function. You probably do it more than 99% of the times you invoke <code>printf()<\/code> (which returns an <code>int<\/code>).<\/p>\n<p>However, as several persons have said in the comments, you called your function <code>strlen()<\/code> after a standard library function. This is illegal according to C99&#8217;s 7.1.3:2:<\/p>\n<blockquote>\n<p>If the program declares or defines an identifier in a context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved identifier as a macro name, the behavior is undefined.<\/p>\n<\/blockquote>\n<p>Here the compiler warns unexpectedly, and either calls the standard function instead of yours, or calls no function at all (since it knows <strong>its<\/strong> <code>strlen()<\/code> is supposed to be without side-effects). This is one of the things undefined behavior can do.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:27:07. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>It is perfectly legal to ignore the return value of a function. You probably do it more than 99% of the times you invoke printf() (which returns an int). However, as several persons have said in the comments, you called your function strlen() after a standard library function. This is illegal according to C99&#8217;s 7.1.3:2: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-679","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=679"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/679\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}