{"id":1590,"date":"2013-02-11T11:55:58","date_gmt":"2013-02-11T19:55:58","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1590"},"modified":"2013-02-11T11:55:58","modified_gmt":"2013-02-11T19:55:58","slug":"turning-the-complier-up-to-11","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1590","title":{"rendered":"Turning the complier up to 11"},"content":{"rendered":"<p>I was tracking down a crash caused by memory not being released and I thought it would be helpful to turn on all the compiler options, thinking that maybe it would point to something I did wrong. It didn&#8217;t help, but it did generate around a thousand warnings. Only two were actual bugs in the code. Most of the rest were conversion warnings. The most common were defining variables as NSInteger when the method that used them was expecting a CGFloat. Second most common were things like this:<br \/>\n<pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\nreturn [[[self fetchedResultsControllerForTableView:tableView] sections] count];\n<\/code><\/pre><br \/>\nObjectAtIndex is an unsigned integer so and count is an NSInteger so to get rid of the warning I just cast count to NSUInteger.<br \/>\n<pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\nreturn [[[[self fetchedResultsControllerForTableView:tableView] sections] objectAtIndex:(NSUInteger)section] name];<\/code><\/pre><\/p>\n<p>And this<br \/>\n<pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\nreturn [[[[self fetchedResultsControllerForTableView:tableView] sections] objectAtIndex:section] numberOfObjects];\n<\/code><\/pre> <\/p>\n<p>which should return an NSInteger rather than an unsigned NSUInteger so here I cast the return value.<br \/>\n<pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\n return (NSInteger)[[[[self fetchedResultsControllerForTableView:tableView] sections] objectAtIndex:(NSUInteger)section] numberOfObjects];\n<\/code><\/pre><\/p>\n<p>Second most common warnings were for unused variables. Since I use the same code for 18 different games I have if statements that determine what the locations of buttons on the screen. Many of the buttons are not used in all of the games so the compiler gives an unused variable warning. To get rid of the warning, I use this line after the last redefinition of the variable. Just so I remember that I&#8217;m using it I put it just before I use the &#8220;unused&#8221; variable. The compiler still compiles correctly when the button is needed, it just doesn\u2019t throw the warning.<\/p>\n<p><pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\n&nbsp;&nbsp;#pragma unused(showHideButtonX)\n&nbsp;&nbsp;#pragma unused(showHideButtonY)\n&nbsp;&nbsp;if ( DISPLAY_SHOWHIDE_BUTTON ) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CGRect showHideFrame = CGRectMake(showHideButtonX, showHideButtonY, buttonsSize, buttonsSize);\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was tracking down a crash caused by memory not being released and I thought it would be helpful to turn on all the compiler options, thinking that maybe it would point to something I did wrong. It didn&#8217;t help, but it did generate around a thousand warnings. Only two were actual bugs in the &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1590\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Turning the complier up to 11<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1590","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1590"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1590\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}