{"id":1101,"date":"2012-04-26T12:31:09","date_gmt":"2012-04-26T18:31:09","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=1101"},"modified":"2012-04-26T12:57:48","modified_gmt":"2012-04-26T18:57:48","slug":"help-me-runtime-debug-this-code","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2012\/04\/26\/help-me-runtime-debug-this-code\/","title":{"rendered":"Help me runtime debug this code"},"content":{"rendered":"<p>Hey there&#8230; This happens to me sometimes.  I want to be able to turn on a debug mode or a tool that will crash my code during runtime.  I can use Xcode, MSVC 2008, or GCC under Linux.  Anything.  Though, XCode is preferred.  This must work with C++, not just C code.<\/p>\n<pre>\r\n\/\/ I don't want to change my code.  I don't want to use Array templates.\r\n\/\/ I just want a debugging tool that will crash my code when I do \r\n\/\/ array out-of-bounds, even if they are \"safe.\"  Here's my example.\r\n\r\nstruct Goods {\r\n    int x[10];\r\n    int y[10];\r\n    int z[10];\r\n};\r\n\r\nint main(int argc, char *argv[]) {\r\n    Goods data;\r\n    \r\n    int k = 11;\r\n    for (int i=0; i&lt;k; i++) { data.y[i] = 1; } \/\/ SHOULD ERROR ON i == 10\r\n\r\n    int j = -1;\r\n    for (int i=j; i&lt;10; i++) { data.y[i] = 1; } \/\/ SHOULD ERROR ON i == -1\r\n \r\n    return 0;\r\n}\r\n<\/pre>\n<p>Changing my code, using STL, using &#8220;new&#8221;, using &#8220;malloc&#8221; are not options.<\/p>\n<p>Help me!<br \/>\n-Phil<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey there&#8230; This happens to me sometimes. I want to be able to turn on a debug mode or a tool that will crash my code during runtime. I can use Xcode, MSVC 2008, or GCC under Linux. Anything. Though, XCode is preferred. This must work with C++, not just C code. \/\/ I don&#8217;t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-1101","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/1101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=1101"}],"version-history":[{"count":9,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/1101\/revisions"}],"predecessor-version":[{"id":1110,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/1101\/revisions\/1110"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=1101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=1101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=1101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}