{"id":11163,"date":"2008-04-21T11:41:17","date_gmt":"2008-04-21T08:41:17","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=11163"},"modified":"2008-04-21T11:41:17","modified_gmt":"2008-04-21T08:41:17","slug":"thou-shalt-not-ignore-warnings","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2008\/04\/21\/thou-shalt-not-ignore-warnings\/","title":{"rendered":"Thou shalt not ignore warnings"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>Here is a quote from <a href=\"http:\/\/books.slashdot.org\/comments.pl?sid=521796&amp;cid=23068006\">a wise comment<\/a> in the discussion of the <a href=\"http:\/\/news.slashdot.org\/article.pl?sid=08\/04\/14\/1415215&#038;from=rss\">&#8220;Linux system programming&#8221; book review<\/a>:<\/p>\n<blockquote><p>Build your code with -Wall -Werror (or your compiler&#8217;s equivalent). Once you clean up all the crud, that pops up, crank it up with -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith. Once there \u2014 add -Wreturn-type -Wcast-qual -Wswitch -Wshadow -Wcast-align and tighten up by removing the no in -Wno-unused-parameter. The -Wwrite-strings is essential, if you wish your code to be compiled with a C++ compiler some day (hint: the correct type for static strings is &#8221; const char *&#8221;).<br \/>\nFor truly clean code, add -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls.<br \/>\nThe people, who wrote and maintain the compiler, are, most likely, several levels above you in understanding programming in general and C-programming in particular. Ignoring the advice their code generates is foolish on your part&#8230;<br \/>\nAs a minimum, solved warnings will make your code more readable by reducing\/eliminating the &#8220;Why is he doing this?&#8221; questions. More often than not, they point out bugs you would otherwise spend hours chasing with a debugger later.<br \/>\nAnd they make your code more portable. But if you don&#8217;t understand, why a warning is generated \u2014 ask around. Don&#8217;t just &#8220;shut it up&#8221;. For example, initializing a variable at declaration is usually a no-no. If the compiler thinks, the variable may be used before being initialized, scrutinize your program&#8217;s flow. If you can&#8217;t figure out, it may some times be better to disable this one warning temporarily with -Wno-uninitialized to move on, instead of shutting it up for ever by a bogus &#8220;= 0&#8221; or some such&#8230;<\/p><\/blockquote>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>Here is a quote from a wise comment in the discussion of the &#8220;Linux system programming&#8221; book review: Build your code with -Wall -Werror (or your compiler&#8217;s equivalent). Once you clean up all the crud, that pops up, crank it up with -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith. Once there \u2014 add -Wreturn-type -Wcast-qual -Wswitch -Wshadow &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2008\/04\/21\/thou-shalt-not-ignore-warnings\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Thou shalt not ignore warnings<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_links_to":"","_links_to_target":""},"categories":[1,6,18],"tags":[1494,471,74],"keyring_services":[],"class_list":["post-11163","post","type-post","status-publish","format-standard","hentry","category-general","category-linux","category-programming","tag-c","tag-compilers","tag-tips"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":10451,"url":"https:\/\/mamchenkov.net\/wordpress\/2006\/09\/05\/your-own-compiler-should-you-or-should-you-not\/","url_meta":{"origin":11163,"position":0},"title":"Your own compiler &#8211; should you or should you not?","author":"Leonid Mamchenkov","date":"September 5, 2006","format":false,"excerpt":"Joel Spolsky shares why they have their own compiler and how long it took them to write it. Most people don't realize that writing a compiler like this is only about 2 months work for one talented person who read the Dragon book. While compilers seem like a thing of\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10064,"url":"https:\/\/mamchenkov.net\/wordpress\/2006\/04\/21\/daily-del-icio-us-bookmarks\/","url_meta":{"origin":11163,"position":1},"title":"Daily del.icio.us bookmarks","author":"Leonid Mamchenkov","date":"April 21, 2006","format":false,"excerpt":"Shared bookmarks for del.icio.us user tvset on 2006-04-20 The LEX & YACC Page Tagged as: bison code compiler development flex gnu language lex links parser programming scripting software syntax technology tools translation unix work yacc","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":29107,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/12\/18\/bash-parameter-expansion\/","url_meta":{"origin":11163,"position":2},"title":"Bash parameter expansion","author":"Leonid Mamchenkov","date":"December 18, 2018","format":false,"excerpt":"If you've ever written a bash script with variables, and know that it wasn't your last one,\u00a0 I promise you, you'll love this wiki page.\u00a0 It covers a whole lot of different ways to expand and manipulate variable values in bash, all on a single, conveniently organized page.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":14768,"url":"https:\/\/mamchenkov.net\/wordpress\/2011\/04\/18\/command-line-php\/","url_meta":{"origin":11163,"position":3},"title":"Command line PHP","author":"Leonid Mamchenkov","date":"April 18, 2011","format":false,"excerpt":"I've discovered two things about command line PHP today. \u00a0I'll share them here just in case you missed them too. First, the \"-f\" parameter is optional. \u00a0I'm not sure when the change happened, but I'm pretty sure back when I started using it, it was required. \u00a0Now, instead of \"php\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2011\/04\/php-interactive-shell.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":27105,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/12\/11\/php-static-analysis-tool-discover-bugs-in-your-code-without-running-it\/","url_meta":{"origin":11163,"position":4},"title":"PHP Static Analysis Tool &#8211; discover bugs in your code without running it!","author":"Leonid Mamchenkov","date":"December 11, 2016","format":false,"excerpt":"Ond\u0159ej Mirtes shares the idea behind the creation of\u00a0PHPStan - a static analysis tool for PHP: Compiled languages need to know about the type of every variable, return type of every method etc. before the program runs. This is why the compiler needs to make sure that the program is\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":28847,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/10\/09\/php-safe-and-rector\/","url_meta":{"origin":11163,"position":5},"title":"PHP Safe and Rector","author":"Leonid Mamchenkov","date":"October 9, 2018","format":false,"excerpt":"I came across a couple of very interesting PHP libraries today. The first one is\u00a0thecodingmachine\/safe.\u00a0 This library wraps all PHP functions that return false on failure into another function that throws the exception instead. Think of all those file_get_contents() and json_decode() situations you had to code around.\u00a0 Not anymore.\u00a0 You\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/11163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=11163"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/11163\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=11163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=11163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=11163"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=11163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}