{"id":29843,"date":"2006-09-06T10:00:07","date_gmt":"2006-09-06T10:00:07","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/09\/06\/you-already-know-what-your-target-architecture-is-or-at-least-you-should\/"},"modified":"2006-09-06T10:00:07","modified_gmt":"2006-09-06T10:00:07","slug":"you-already-know-what-your-target-architecture-is-or-at-least-you-should","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20060906-07\/?p=29843","title":{"rendered":"You already know what your target architecture is (or at least you should)"},"content":{"rendered":"<p>\nSometimes the questions I see make me shake my head in wonderment.\n<\/p>\n<blockquote CLASS=\"q\"><p>\nHow do I determine programmatically what processor architecture\nmy program was compiled for?\nI want the x86 version of my program to behave differently from the\nia64 version.\nIs there some API I can call?\n<\/p><\/blockquote>\n<p>\nNote that this person isn&#8217;t asking\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2005\/02\/01\/364563.aspx\">\nwhether the program is running on 64-bit Windows<\/a>.\nThis person wants the program to detect whether it was\ncompiled with an x86 compiler, an ia64 compiler, an amd64\ncompiler, or whatever.\n<\/p>\n<p>\nBut why do you need an API for this?\nYou already know what your target architecture is\nbecause you compiled it yourself!\n<\/p>\n<p>\nIt so happens that the Microsoft Visual C++ compiler\n<a HREF=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/b0084kay.aspx\">\ndefines several symbols for you automatically<\/a>\n(assuming you&#8217;re not running\nthe compiler in &#8220;strict ANSI compliance mode&#8221;).\nIf you&#8217;re willing to tie yourself to the Microsoft Visual C++ compiler,\nyou can use those symbols.\n<\/p>\n<pre>\n#ifdef _M_IX86\n    \/\/ the target architecture is x86\n#else\n    \/\/ the target architecture is something else\n#endif\n<\/pre>\n<p>\nIf you don&#8217;t want to tie yourself to a particular compiler,\nyou&#8217;ll have to pass that information yourself.\nFor example, you could have your x86 <code>makefile<\/code> pass\n<code>-DBUILDING_FOR_x86<\/code> in the compiler flags,\nwhile having the ia64 <code>makefile<\/code> pass\n<code>-DBUILDING_FOR_ia64<\/code>, and so on.\nThis is the approach used by the <code>build<\/code> utility\nthat comes with the Windows DDK:\nThe DDK&#8217;s makefile system defines a variety\nof symbols that programs (and other makefiles) can use to alter their\nbehavior depending on the compilation environment:\n<\/p>\n<pre>\n\/\/ assumes you use makefile.def\n#if defined(_X86_)\n    \/\/ the target architecture is x86\n#elif defined(_IA64_)\n    \/\/ the target architecture is Intel ia64\n#elif defined(_AMD64_)\n    \/\/ the target architecture is AMD x86-64\n#else\n    \/\/ some other architecture\n#endif\n<\/pre>\n<p>\nAs we saw in the earlier article,\nyou can also use the <code>_WIN64<\/code> symbol to detect that\nthe target platform is 64-bit Windows.\n<\/p>\n<p>\nBut the point is that this is all something you control yourself.\nYou&#8217;re the one who is compiling the program.\nYou know what your target architecture is.\nNo need to ask somebody to tell you something that is already\nentirely under your own control.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes the questions I see make me shake my head in wonderment. How do I determine programmatically what processor architecture my program was compiled for? I want the x86 version of my program to behave differently from the ia64 version. Is there some API I can call? Note that this person isn&#8217;t asking whether the [&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":[25],"class_list":["post-29843","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Sometimes the questions I see make me shake my head in wonderment. How do I determine programmatically what processor architecture my program was compiled for? I want the x86 version of my program to behave differently from the ia64 version. Is there some API I can call? Note that this person isn&#8217;t asking whether the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/29843","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=29843"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/29843\/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=29843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=29843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=29843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}