{"id":1240,"date":"2012-09-21T10:12:09","date_gmt":"2012-09-20T22:12:09","guid":{"rendered":"https:\/\/www.deltics.co.nz\/blog\/?p=1240"},"modified":"2012-09-21T10:13:26","modified_gmt":"2012-09-20T22:13:26","slug":"whats-in-a-word","status":"publish","type":"post","link":"https:\/\/www.deltics.co.nz\/blog\/posts\/1240\/","title":{"rendered":"What&#8217;s in a Word &#8230; ?"},"content":{"rendered":"<span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\">&lt; 1<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span><p>In an exchange with David Heffernan both on SO and in the comments here on Te Waka, I had cause to climb in my own personal &#8220;Wayback Machine&#8221; and further investigate an apparent change in compiler behaviour between Delphi 2007 and 2009.<\/p>\n<p>This change was first identified as the result of <a href=\"http:\/\/stackoverflow.com\/questions\/1482699\/zeroconf-bonjour-code-that-works-in-delphi-7-not-working-in-2009\" target=\"_blank\">some code of mine that stopped working in Delphi 2009<\/a>.  The instinctive reaction is &#8220;It must be some Unicode issue&#8221;, but it turned out that the &#8220;problem&#8221; was actually a fix to a compiler bug!<\/p>\n<p><!--more--><\/p>\n<p>To illustrate the bug that was fixed, compile and run this code in Delphi 2007 or earlier and then compile and run it using Delphi 2009 or later:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n{$apptype CONSOLE}\r\n\r\nprogram overloads;\r\n\r\nfunction Foo(const aWord: Word): Word; overload;\r\nbegin\r\n  result := 42;\r\nend;\r\n\r\nfunction Foo(const aWord: Longword): Longword; overload;\r\nbegin\r\n  result := 0;\r\nend;\r\n\r\nvar\r\n  i: Integer;\r\nbegin\r\n  i := 300000;\r\n  WriteLn(Foo(i));\r\nend.\r\n<\/pre>\n<p>In Delphi 2007 and earlier, the compiler calls the <em>Word<\/em> version of <strong>Foo()<\/strong>, not the <em>LongWord<\/em>, even though <strong>i<\/strong> is declared as an <em>Integer<\/em> (32-bit) which clearly is too big for a <em>Word<\/em> (16-bit) sized parameter.<\/p>\n<p>It&#8217;s staggering to me that this problem had not bitten me in the rear appendage before that occasion in 2008.<\/p>\n<p>In hindsight it is even more staggering that the compiler did not &#8211; and does not &#8211; emit a warning when an ordinal value is truncated in this fashion.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\">&lt; 1<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span> In an exchange with David Heffernan both on SO and in the comments here on Te Waka, I had cause to climb in my own personal &#8220;Wayback Machine&#8221; and further investigate an apparent change in compiler behaviour between Delphi 2007 and 2009. This change was first identified as the result of some code of mine [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[4],"tags":[187,292],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-k0","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1233,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1233\/","url_meta":{"origin":1240,"position":0},"title":"ReverseBytes()","date":"20 Sep 2012","format":false,"excerpt":"In some comments on StackOverflow, Jeroen asked me to post my code for reversing bytes. Rather than posting code into that question\/answer that wasn't directly relevant to the question\/answer, I decided to quickly throw the code up on here. The intent with ReverseBytes() is - as the name says -\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1397,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1397\/","url_meta":{"origin":1240,"position":1},"title":"Qualified Enum Reference That Fails to Compile in XE4 (and rightly so)","date":"01 May 2013","format":false,"excerpt":"Running through some of my code last night, putting them through the new XE4 compiler, threw up a real oddity: Some code that used to compile just fine, which no longer compiles in XE4 and which should not have compiled before! It's an odd one, because the code previously compiled\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2344,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2344\/","url_meta":{"origin":1240,"position":2},"title":"A Deeper Dive into Range Checking","date":"08 Jun 2015","format":false,"excerpt":"Yesterday I posted about an issue with type checking in Delphi (and other Pascal) compilers. As mentioned in that post, range checking is fundamentally flawed as a supposed solution to the problem for reasons that are explored further in this post. To recap: Range checking does not test the types\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2337,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2337\/","url_meta":{"origin":1240,"position":3},"title":"A Silent Danger&#8230;","date":"07 Jun 2015","format":false,"excerpt":"A brief post on a long standing omission in type checking in Pascal and the limitations of Range Checking as applied to the problem. Consider this contrived example of a simple function: This very simple function accepts an explicitly 32-bit Integer parameter and simply returns TRUE if the value passed\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":349,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/349\/","url_meta":{"origin":1240,"position":4},"title":"Delphi 2009 &#8211; String Performance","date":"18 Sep 2008","format":false,"excerpt":"NOTE: Downloads are now fixed! Andreas Hausladen generously took the time to make some detailed comments on my previous post, one of which prompted me to throw together some further performance test cases for String types specifically.\u00a0 The results were something of a mixed bag and contained some surprises. The\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/delphi2009-stringperformance-resultscapture.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1207,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1207\/","url_meta":{"origin":1240,"position":5},"title":"Adventures in Syntax: Something Old, Something New etc&#8230;","date":"20 Sep 2012","format":false,"excerpt":"As the post title says, this will be a brief detour through some features of the Pascal language and a presentation of some (theoretical) alternatives that could have been introduced instead. That is, some are real but little known syntax, others are what I think might be preferable to the\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1240"}],"collection":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/comments?post=1240"}],"version-history":[{"count":3,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1240\/revisions"}],"predecessor-version":[{"id":1243,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1240\/revisions\/1243"}],"wp:attachment":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=1240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=1240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=1240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}