
{"id":59,"date":"2010-11-02T18:15:43","date_gmt":"2010-11-02T12:45:43","guid":{"rendered":"http:\/\/compilerart.org\/?p=59"},"modified":"2010-11-02T18:15:43","modified_gmt":"2010-11-02T12:45:43","slug":"gcc-limits-and","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2010\/11\/02\/gcc-limits-and\/","title":{"rendered":"gcc limits and -Wformat"},"content":{"rendered":"<div class=\"img-with-text\">\n<a href=\"http:\/\/www.trueangle.org\/wp-content\/uploads\/2011\/01\/50970-paper1-2.pngwp-content\/uploads\/2010\/11\/gcc-wformat.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/compilerart.org\/wp-content\/uploads\/2010\/11\/gcc-wformat-300x226.png\" alt=\"\" title=\"gcc-wformat\" width=\"300\" height=\"226\" class=\"alignleft size-medium wp-image-79\" \/><\/a><br \/>\n<code><br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;limits.h&gt;<br \/>\nint main (void)<br \/>\n{<br \/>\n        unsigned long ul = LONG_MAX;<br \/>\n        short int si = SHRT_MIN;<br \/>\n        printf (\"%d\\n\", ul);<br \/>\n        printf (\"%s\\n\", si);<br \/>\n        return 0;<br \/>\n}<br \/>\n<\/code>\n<\/div>\n<p><code><br \/>\n$gcc printme.c<br \/>\n$.\/a.out<br \/>\n-1<br \/>\nSegmentation fault<br \/>\n$gcc printme.c -Wformat<br \/>\nprintme.c: In function \u2018main\u2019:<br \/>\nprintme.c:7: warning: format \u2018%d\u2019 expects type \u2018int\u2019, but argument 2 has type \u2018long unsigned int\u2019<br \/>\nprintme.c:8: warning: format \u2018%s\u2019 expects type \u2018char *\u2019, but argument 2 has type \u2018int\u2019<br \/>\n $<br \/>\n<\/code><\/p>\n<pre>\nThe &lt;limits.h&gt; header shall define various symbolic names.\nThe names represent various limits on resources that the\nimplementation imposes on applications.\n\nabout \"-Wformat\"\nCheck calls to printf and scanf, etc., to make sure that the\narguments supplied have types appropriate to the format\nstring specified, and that the conversions specified in the\nformat string make sense\n <\/pre>\n<pre>\nReference\/Source:\nThe Definitive Guide to GCC Second Edition\nWilliam von Hagen\nhttp:\/\/www.opengroup.org\/onlinepubs\/009695399\/basedefs\/limits.h.html\nhttp:\/\/gcc.gnu.org\/onlinedocs\/gcc\/Warning-Options.html\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;stdio.h&gt; #include &lt;limits.h&gt; int main (void) { unsigned long ul = LONG_MAX; short int si = SHRT_MIN; printf (&#8220;%d\\n&#8221;, ul); printf (&#8220;%s\\n&#8221;, si); return 0; } $gcc printme.c $.\/a.out -1 Segmentation fault $gcc printme.c -Wformat printme.c: In function \u2018main\u2019: printme.c:7: warning: format \u2018%d\u2019 expects type \u2018int\u2019, but argument 2 has type \u2018long unsigned int\u2019 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2010\/11\/02\/gcc-limits-and\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;gcc limits and -Wformat&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/59"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}