{"id":2966,"date":"2011-01-07T12:46:42","date_gmt":"2011-01-07T17:46:42","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=2966"},"modified":"2014-07-14T10:16:35","modified_gmt":"2014-07-14T14:16:35","slug":"c-macro-tips-and-tricks","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2011\/01\/07\/c-macro-tips-and-tricks\/","title":{"rendered":"C Macro Tips and Tricks"},"content":{"rendered":"<p><a href=\"http:\/\/www.mikeash.com\/pyblog\/friday-qa-2010-12-31-c-macro-tips-and-tricks.html\">Mike Ash<\/a>:<\/p>\r\n<blockquote cite=\"http:\/\/www.mikeash.com\/pyblog\/friday-qa-2010-12-31-c-macro-tips-and-tricks.html\">\r\n<p><code>gcc<\/code> provides two built-in functions which can be useful for building macros.<\/p>\r\n<p>The first is <code>__builtin_types_compatible_p<\/code>. You pass two types to this function (<code>__typeof__<\/code> comes in handy here) and it produces <code>1<\/code> if the two types are &ldquo;compatible&rdquo; (roughly, if they&rsquo;re equal) and <code>0<\/code> if they aren&rsquo;t.<\/p>\r\n<p>The second is <code>__builtin_choose_expr<\/code>. This works like the C standard <code>?:<\/code> operator, except that the predicate must be a compile-time constant, and the type of the entire <code>__builtin_choose_expr<\/code> expression is the type of whichever branch gets chosen; the two branches are not required to be similar types.<\/p>\r\n<\/blockquote>\r\n<p>A good compilation of notes.<\/p>","protected":false},"excerpt":{"rendered":"<p>Mike Ash: gcc provides two built-in functions which can be useful for building macros. The first is __builtin_types_compatible_p. You pass two types to this function (__typeof__ comes in handy here) and it produces 1 if the two types are &ldquo;compatible&rdquo; (roughly, if they&rsquo;re equal) and 0 if they aren&rsquo;t. The second is __builtin_choose_expr. This works [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[45,285,941,71],"class_list":["post-2966","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-c","tag-gcc","tag-macros","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=2966"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2966\/revisions"}],"predecessor-version":[{"id":9143,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2966\/revisions\/9143"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=2966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=2966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=2966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}