{"id":35183,"date":"2005-06-28T10:00:07","date_gmt":"2005-06-28T10:00:07","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/06\/28\/why-do-microsoft-code-samples-tend-to-use-zeromemory-instead-of-0\/"},"modified":"2005-06-28T10:00:07","modified_gmt":"2005-06-28T10:00:07","slug":"why-do-microsoft-code-samples-tend-to-use-zeromemory-instead-of-0","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050628-07\/?p=35183","title":{"rendered":"Why do Microsoft code samples tend to use ZeroMemory instead of { 0 }?"},"content":{"rendered":"<p>If you go browsing around MSDN, you&#8217;ll find that <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/sysinfo\/base\/verifying_the_system_version.asp\"> code samples tend to call <code>ZeroMemory<\/code> explicitly<\/a> rather than using &#8220;<code>= { 0 }<\/code>&#8221; notation. Why is that?\n To make it clearer for people who are used to other programming languages.\n Like it or not, a significant percentage of people who write programs for Windows do it in languages other than C and C++. Although those developers may have a basic understanding of C and C++, they don&#8217;t have all the language subtleties memorized.\n Compare the situation of speaking in English to a group of people where not everyone speaks the language fluently. If you&#8217;re considerate of your audience, you&#8217;re going to avoid the more esoteric grammatical constructions, the rare words, and the obscure idioms. Instead of saying, &#8220;Were it to rain, we will see that umbrellas be available,&#8221; you would use the simpler &#8220;If it rains, then we will make sure that umbrellas are available,&#8221; thereby avoiding the grammatical complexity of the implied conditional by inversion (&#8220;if&#8221;), the subjunctive of condition (&#8220;were&#8221;), the implied conclusion (&#8220;then&#8221;), and the subjunction of intention (&#8220;be&#8221;).\n Heck, even people who claim to know C and C++ don&#8217;t have all the language subtleties memorized. Some of them have false impressions of what &#8220;<code> = { 0 }<\/code>&#8221; does. And who among us really has C\/C++&#8217;s bizarre operator precedence rules committed to memory?\n Consequently, MSDN samples tend to use <code>ZeroMemory<\/code> to make it blindingly obvious what is being set to zero. One of the things we&#8217;ve learned over the years is that many people just copy\/paste sample code without understanding it. If there are little things like <code>ZeroMemory<\/code> that can be done to make the intent of sample code clearer and reduce translation errors, then that&#8217;s a good thing.<\/p>\n<p> If you prefer &#8220;<code> = { 0 }<\/code>&#8220;, then go ahead and use it, secure in the knowledge that thousands of programmers aren&#8217;t going to read your code and try to translate it into Visual Basic because that&#8217;s the only language they know. But MSDN doesn&#8217;t have that luxury. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you go browsing around MSDN, you&#8217;ll find that code samples tend to call ZeroMemory explicitly rather than using &#8220;= { 0 }&#8221; notation. Why is that? To make it clearer for people who are used to other programming languages. Like it or not, a significant percentage of people who write programs for Windows do [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-35183","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>If you go browsing around MSDN, you&#8217;ll find that code samples tend to call ZeroMemory explicitly rather than using &#8220;= { 0 }&#8221; notation. Why is that? To make it clearer for people who are used to other programming languages. Like it or not, a significant percentage of people who write programs for Windows do [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=35183"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35183\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=35183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=35183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=35183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}