{"id":305,"date":"2006-08-31T20:55:12","date_gmt":"2006-09-01T03:55:12","guid":{"rendered":"http:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/"},"modified":"2020-07-25T23:28:48","modified_gmt":"2020-07-26T06:28:48","slug":"variable-declaration-guidelines","status":"publish","type":"post","link":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/","title":{"rendered":"Variable Declaration Guidelines"},"content":{"rendered":"<p>Back in 2000, I came across this Advogato article about <a href=\"http:\/\/advogato.org\/article\/97.html\">proper coding guidelines<\/a> for the coming wave of 64-bit machines. The most interesting part, I thought, was <a href=\"http:\/\/advogato.org\/article\/97.html#2\">comment #2 (&#8220;C is portable, if you let it be&#8221;)<\/a> which offers some very sane guidelines for declaring variable types to just allow the compiler to do its job effectively. This is why I usually just declare int&#8217;s for numbers rather than uint32_t&#8217;s everywhere. There is often no reason to try to force particular types.<\/p>\n<p>Don&#8217;t think that you&#8217;re saving space by declaring a uint8_t instead of an int&#8211; chances are that you aren&#8217;t. I&#8217;ve disassembled enough C code compiled into 32-bit x86 machine code to know that a compiler will usually allocate 32 bits for that 8-bit variable. In fact, here is a small piece of code to drive the point home:<\/p>\n<p>stack.c:<br \/>\n<script src=\"https:\/\/gist.github.com\/multimediamike\/3b734488442b473835f8d9492793a6c5.js\"><\/script><\/p>\n<p>Compile with: gcc -Wall stack.c -o stack<br \/>\nDisassemble with: objdump -d -Mintel stack<br \/>\nKey parts:<\/p>\n<pre>\r\n080483a0 < main >:\r\n 80483a0:   55                  push   ebp\r\n 80483a1:   89 e5               mov    ebp,esp\r\n 80483a3:   83 ec 08            sub    esp,0x8\r\n 80483a6:   83 e4 f0            and    esp,0xfffffff0\r\n 80483a9:   b8 00 00 00 00      mov    eax,0x0\r\n 80483ae:   29 c4               sub    esp,eax\r\n 80483b0:   e8 07 ff ff ff      call   80482bc < random @plt >\r\n 80483b5:   88 45 ff            mov    BYTE PTR [ebp-1],al\r\n 80483b8:   66 0f be 45 ff      movsx  ax,BYTE PTR [ebp-1]\r\n 80483bd:   40                  inc    eax\r\n 80483be:   66 89 45 fc         mov    WORD PTR [ebp-4],ax\r\n<\/pre>\n<p>Notice that, despite strictly needing only 3 bytes of local variable storage, 8 bytes were allocated from the stack. 32-bit machines like the i386 really, really like dealing with 32-bit quantities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in 2000, I came across this Advogato article about proper coding guidelines for the coming wave of 64-bit machines. The most interesting part, I thought, was comment #2 (&#8220;C is portable, if you let it be&#8221;) which offers some very sane guidelines for declaring variable types to just allow the compiler to do its [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-305","post","type-post","status-publish","format-standard","hentry","category-programming"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Back in 2000, I came across this Advogato article about proper coding guidelines for the coming wave of 64-bit machines. The most interesting part, I thought, was comment #2 (&quot;C is portable, if you let it be&quot;) which offers some very sane guidelines for declaring variable types to just allow the compiler to do its\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Multimedia Mike\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Breaking Eggs And Making Omelettes | Topics On Multimedia Technology and Reverse Engineering\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Variable Declaration Guidelines | Breaking Eggs And Making Omelettes\" \/>\n\t\t<meta property=\"og:description\" content=\"Back in 2000, I came across this Advogato article about proper coding guidelines for the coming wave of 64-bit machines. The most interesting part, I thought, was comment #2 (&quot;C is portable, if you let it be&quot;) which offers some very sane guidelines for declaring variable types to just allow the compiler to do its\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2006-09-01T03:55:12+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-07-26T06:28:48+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Variable Declaration Guidelines | Breaking Eggs And Making Omelettes\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Back in 2000, I came across this Advogato article about proper coding guidelines for the coming wave of 64-bit machines. The most interesting part, I thought, was comment #2 (&quot;C is portable, if you let it be&quot;) which offers some very sane guidelines for declaring variable types to just allow the compiler to do its\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/#article\",\"name\":\"Variable Declaration Guidelines | Breaking Eggs And Making Omelettes\",\"headline\":\"Variable Declaration Guidelines\",\"author\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#organization\"},\"datePublished\":\"2006-08-31T20:55:12-07:00\",\"dateModified\":\"2020-07-25T23:28:48-07:00\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/#webpage\"},\"articleSection\":\"Programming\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/multimedia.cx\\\/eggs\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/programming\\\/#listItem\",\"name\":\"Programming\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/programming\\\/#listItem\",\"position\":2,\"name\":\"Programming\",\"item\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/programming\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/#listItem\",\"name\":\"Variable Declaration Guidelines\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/#listItem\",\"position\":3,\"name\":\"Variable Declaration Guidelines\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/programming\\\/#listItem\",\"name\":\"Programming\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#organization\",\"name\":\"Breaking Eggs And Making Omelettes\",\"description\":\"Topics On Multimedia Technology and Reverse Engineering\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/\",\"name\":\"Multimedia Mike\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2eb93f7cada658f7986b5092062849fa255779eada3342c8f6b9a40764b95fdd?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"Multimedia Mike\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/#webpage\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/\",\"name\":\"Variable Declaration Guidelines | Breaking Eggs And Making Omelettes\",\"description\":\"Back in 2000, I came across this Advogato article about proper coding guidelines for the coming wave of 64-bit machines. The most interesting part, I thought, was comment #2 (\\\"C is portable, if you let it be\\\") which offers some very sane guidelines for declaring variable types to just allow the compiler to do its\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/variable-declaration-guidelines\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\"},\"datePublished\":\"2006-08-31T20:55:12-07:00\",\"dateModified\":\"2020-07-25T23:28:48-07:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#website\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/\",\"name\":\"Breaking Eggs And Making Omelettes\",\"description\":\"Topics On Multimedia Technology and Reverse Engineering\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Variable Declaration Guidelines | Breaking Eggs And Making Omelettes","description":"Back in 2000, I came across this Advogato article about proper coding guidelines for the coming wave of 64-bit machines. The most interesting part, I thought, was comment #2 (\"C is portable, if you let it be\") which offers some very sane guidelines for declaring variable types to just allow the compiler to do its","canonical_url":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/#article","name":"Variable Declaration Guidelines | Breaking Eggs And Making Omelettes","headline":"Variable Declaration Guidelines","author":{"@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author"},"publisher":{"@id":"https:\/\/multimedia.cx\/eggs\/#organization"},"datePublished":"2006-08-31T20:55:12-07:00","dateModified":"2020-07-25T23:28:48-07:00","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/#webpage"},"isPartOf":{"@id":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/#webpage"},"articleSection":"Programming"},{"@type":"BreadcrumbList","@id":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs#listItem","position":1,"name":"Home","item":"https:\/\/multimedia.cx\/eggs","nextItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/category\/programming\/#listItem","name":"Programming"}},{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/category\/programming\/#listItem","position":2,"name":"Programming","item":"https:\/\/multimedia.cx\/eggs\/category\/programming\/","nextItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/#listItem","name":"Variable Declaration Guidelines"},"previousItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/#listItem","position":3,"name":"Variable Declaration Guidelines","previousItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/category\/programming\/#listItem","name":"Programming"}}]},{"@type":"Organization","@id":"https:\/\/multimedia.cx\/eggs\/#organization","name":"Breaking Eggs And Making Omelettes","description":"Topics On Multimedia Technology and Reverse Engineering","url":"https:\/\/multimedia.cx\/eggs\/"},{"@type":"Person","@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author","url":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/","name":"Multimedia Mike","image":{"@type":"ImageObject","@id":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/2eb93f7cada658f7986b5092062849fa255779eada3342c8f6b9a40764b95fdd?s=96&d=identicon&r=g","width":96,"height":96,"caption":"Multimedia Mike"}},{"@type":"WebPage","@id":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/#webpage","url":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/","name":"Variable Declaration Guidelines | Breaking Eggs And Making Omelettes","description":"Back in 2000, I came across this Advogato article about proper coding guidelines for the coming wave of 64-bit machines. The most interesting part, I thought, was comment #2 (\"C is portable, if you let it be\") which offers some very sane guidelines for declaring variable types to just allow the compiler to do its","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/multimedia.cx\/eggs\/#website"},"breadcrumb":{"@id":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/#breadcrumblist"},"author":{"@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author"},"creator":{"@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author"},"datePublished":"2006-08-31T20:55:12-07:00","dateModified":"2020-07-25T23:28:48-07:00"},{"@type":"WebSite","@id":"https:\/\/multimedia.cx\/eggs\/#website","url":"https:\/\/multimedia.cx\/eggs\/","name":"Breaking Eggs And Making Omelettes","description":"Topics On Multimedia Technology and Reverse Engineering","inLanguage":"en-US","publisher":{"@id":"https:\/\/multimedia.cx\/eggs\/#organization"}}]},"og:locale":"en_US","og:site_name":"Breaking Eggs And Making Omelettes | Topics On Multimedia Technology and Reverse Engineering","og:type":"article","og:title":"Variable Declaration Guidelines | Breaking Eggs And Making Omelettes","og:description":"Back in 2000, I came across this Advogato article about proper coding guidelines for the coming wave of 64-bit machines. The most interesting part, I thought, was comment #2 (&quot;C is portable, if you let it be&quot;) which offers some very sane guidelines for declaring variable types to just allow the compiler to do its","og:url":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/","article:published_time":"2006-09-01T03:55:12+00:00","article:modified_time":"2020-07-26T06:28:48+00:00","twitter:card":"summary","twitter:title":"Variable Declaration Guidelines | Breaking Eggs And Making Omelettes","twitter:description":"Back in 2000, I came across this Advogato article about proper coding guidelines for the coming wave of 64-bit machines. The most interesting part, I thought, was comment #2 (&quot;C is portable, if you let it be&quot;) which offers some very sane guidelines for declaring variable types to just allow the compiler to do its"},"aioseo_meta_data":{"post_id":"305","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2020-12-31 21:51:44","updated":"2025-12-31 18:34:28","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/multimedia.cx\/eggs\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/multimedia.cx\/eggs\/category\/programming\/\" title=\"Programming\">Programming<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tVariable Declaration Guidelines\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/multimedia.cx\/eggs"},{"label":"Programming","link":"https:\/\/multimedia.cx\/eggs\/category\/programming\/"},{"label":"Variable Declaration Guidelines","link":"https:\/\/multimedia.cx\/eggs\/variable-declaration-guidelines\/"}],"_links":{"self":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/comments?post=305"}],"version-history":[{"count":2,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/305\/revisions"}],"predecessor-version":[{"id":4627,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/305\/revisions\/4627"}],"wp:attachment":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/media?parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/categories?post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/tags?post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}