{"id":55,"date":"2021-03-01T20:28:15","date_gmt":"2021-03-01T20:28:15","guid":{"rendered":"http:\/\/danielpgleason.com\/?p=55"},"modified":"2021-03-01T20:29:53","modified_gmt":"2021-03-01T20:29:53","slug":"what-is-the-build-order-of-a-c-program-interview-questions","status":"publish","type":"post","link":"https:\/\/danielpgleason.com\/index.php\/2021\/03\/01\/what-is-the-build-order-of-a-c-program-interview-questions\/","title":{"rendered":"What is the build order of a C program? (Interview Questions)"},"content":{"rendered":"\n<p>Today I had an interview and I incorrectly answered a question. It was silly because I remember reading about this a long time ago honestly in a C++ book written by IBM from the 1990s. It&#8217;s one of the first books I read growing up when learning to code. My mother bought it for me from Salvation Army. It had a yellowish-orange and red cover. Anyways, just as a personal note and so that I don&#8217;t forget this again. <\/p>\n\n\n\n<p>The order is as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Preprocessing &#8211; this is essentially the stage where the preprocessor parses the source files and looks for macros. This one is the one I&#8217;m most familiar with due to my heavy usage of Unreal Engine. Unreal Engine uses a lot of macros, and conditional compilation instructions. <\/li><\/ul>\n\n\n\n<p>Just as an example, in unreal engine there&#8217;s tons of conditional compilation instructions like this:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#if WITH_SERVER_CODE\n#endif\n\n#if WITH_EDITOR\n#endif<\/code><\/pre><\/div>\n\n\n\n<p>There&#8217;s more information about the visual studio C++ preprocessor here: https:\/\/docs.microsoft.com\/en-us\/cpp\/preprocessor\/c-cpp-preprocessor-reference?view=msvc-160<\/p>\n\n\n\n<p>The preprocessor is really amazing honestly. There&#8217;s some token-pasting operations using the ## tag in a macro. I found this example on here: https:\/\/docs.microsoft.com\/en-us\/cpp\/preprocessor\/token-pasting-operator-hash-hash?view=msvc-160<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plane\"><code>#define paster( n ) printf_s( &quot;token&quot; #n &quot; = %d&quot;, token##n )\nint token10 = 15;<\/code><\/pre><\/div>\n\n\n\n<p>So essentially, if we call paster(10). It will essentially put token10 as the last parameter and it will fill in 15 where #n is at. So this will cause the console to print out &#8220;token10 = 15&#8221; There are other examples of preprocessor usage but those can be looked at on the reference I linked above.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Compilation &#8211; This is basically where the compiler goes over the code again (after it has been filled in with proper pre-processor changes) and then it begins to generate assembly source code.<\/li><li>Assembly &#8211; Takes assembly source code and builds an object file.<\/li><li>Linking &#8211; Takes libraries and object files to create the executable file. <\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I had an interview and I incorrectly answered a question. It was silly because I remember reading about this a long time ago honestly in a C++ book written by IBM from the 1990s. It&#8217;s one of the first books I read growing up when learning to code. My mother bought it for me &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/danielpgleason.com\/index.php\/2021\/03\/01\/what-is-the-build-order-of-a-c-program-interview-questions\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;What is the build order of a C program? (Interview Questions)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[20],"tags":[],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-interview-questions"],"_links":{"self":[{"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/posts\/55"}],"collection":[{"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":1,"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":56,"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/posts\/55\/revisions\/56"}],"wp:attachment":[{"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danielpgleason.com\/index.php\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}