{"id":1623,"date":"2009-05-06T16:59:54","date_gmt":"2009-05-06T06:59:54","guid":{"rendered":"http:\/\/www.flamingspork.com\/blog\/?p=1623"},"modified":"2016-08-22T15:09:36","modified_gmt":"2016-08-22T05:09:36","slug":"c-stl-bitset-only-useful-for-known-at-compile-time-number-of-bits","status":"publish","type":"post","link":"https:\/\/www.flamingspork.com\/blog\/2009\/05\/06\/c-stl-bitset-only-useful-for-known-at-compile-time-number-of-bits\/","title":{"rendered":"c++ stl bitset only useful for known-at-compile-time number of bits"},"content":{"rendered":"<p>Found in the<a href=\"http:\/\/web.archive.org\/web\/20130628174840\/http:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/manual\/bitset.html\"> libstdc++ docs<\/a>:<\/p>\n<blockquote><p>Extremely weird solutions.   If you have access to the compiler and linker at runtime, you can do something insane, like figuring out just how many bits you need, then writing a temporary source code file. That file contains an instantiation of bitset for the required number of bits, inside some wrapper functions with unchanging signatures. Have your program then call the compiler on that file using Position Independent Code, then open the newly-created object file and load those wrapper functions. You&#8217;ll have an instantiation of bitset for the exact N that you need at the time. Don&#8217;t forget to delete the temporary files. (Yes, this can be, and has been, done.)<\/p><\/blockquote>\n<p>Oh yeah &#8211; feel the love.<\/p>\n<p>Brought to you by the stl-is-often-worse-for-you-than-meth dept.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Found in the libstdc++ docs: Extremely weird solutions. If you have access to the compiler and linker at runtime, you can do something insane, like figuring out just how many bits you need, then writing a temporary source code file. &hellip; <a href=\"https:\/\/www.flamingspork.com\/blog\/2009\/05\/06\/c-stl-bitset-only-useful-for-known-at-compile-time-number-of-bits\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[76,75,18],"tags":[],"class_list":["post-1623","post","type-post","status-publish","format-standard","hentry","category-code","category-drizzle-work-et-al","category-grumble"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5a6n8-qb","jetpack-related-posts":[{"id":2323,"url":"https:\/\/www.flamingspork.com\/blog\/2011\/03\/17\/things-ive-done-in-drizzle\/","url_meta":{"origin":1623,"position":0},"title":"Things I&#8217;ve done in Drizzle","author":"Stewart Smith","date":"2011-03-17","format":false,"excerpt":"When writing my Dropping ACID: Eating Data in a Web 2.0 Cloud World talk for LCA2011 I came to the realisation that I had forgotten a lot of the things I had worked on in MySQL and MySQL Cluster. So, as a bit of a retrospective as part of the\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3906,"url":"https:\/\/www.flamingspork.com\/blog\/2014\/11\/14\/c-bitfields-considered-harmful\/","url_meta":{"origin":1623,"position":1},"title":"C bitfields considered harmful","author":"Stewart Smith","date":"2014-11-14","format":false,"excerpt":"In C (and C++) you can specify that a variable should take a specific number of bits of storage by doing \"uint32_t foo:4;\" rather than just \"uint32_t foo\". In this example, the former uses 4 bits while the latter uses 32bits. This can be useful to pack many bit fields\u2026","rel":"","context":"In &quot;code&quot;","block_context":{"text":"code","link":"https:\/\/www.flamingspork.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1008,"url":"https:\/\/www.flamingspork.com\/blog\/2008\/02\/11\/getting-a-file-size-on-windows\/","url_meta":{"origin":1623,"position":2},"title":"Getting a file size (on Windows)","author":"Stewart Smith","date":"2008-02-11","format":false,"excerpt":"The first point I'd like to make is that you're using a Microsoft Windows API, so you have already lost. You are just not quite aware of how much you have lost. A quick look around and you say \"Ahh... GetFileSize, that's what I want to do!\" Except, of course,\u2026","rel":"","context":"In &quot;grumble&quot;","block_context":{"text":"grumble","link":"https:\/\/www.flamingspork.com\/blog\/category\/grumble\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2196,"url":"https:\/\/www.flamingspork.com\/blog\/2010\/11\/15\/limiting-functions-to-32k-stack-in-drizzle-and-scoped_ptr\/","url_meta":{"origin":1623,"position":3},"title":"Limiting functions to 32k stack in Drizzle (and scoped_ptr)","author":"Stewart Smith","date":"2010-11-15","format":false,"excerpt":"I wonder if this comes under \"Code Style\" or not... Anyway, Monty and I finished getting Drizzle ready for adding \"\u00ef\u00bb\u00bf\u00ef\u00bb\u00bf\u00ef\u00bb\u00bf-Wframe-larger-than=32768\" as a standard compiler flag. This means that no function within the Drizzle source tree can use greater than 32kb stack - it's a compiler warning - and with\u2026","rel":"","context":"In &quot;code&quot;","block_context":{"text":"code","link":"https:\/\/www.flamingspork.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2330,"url":"https:\/\/www.flamingspork.com\/blog\/2011\/03\/24\/drizzle-online-backup-with-xtrabackup\/","url_meta":{"origin":1623,"position":4},"title":"Drizzle online backup with xtrabackup","author":"Stewart Smith","date":"2011-03-24","format":false,"excerpt":"For backups, historically in the MySQL world you've had mysqldump (a SQL dump, means on restore you have to rebuild indexes), InnoDB Hot Backup (proprietary, but takes a copy of the InnoDB data files, so restore is much quicker), LVM snapshots (various scripts exist, does have larger IO impact, requires\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2136,"url":"https:\/\/www.flamingspork.com\/blog\/2010\/09\/23\/warnings-are-now-actual-problems\/","url_meta":{"origin":1623,"position":5},"title":"Warnings are now actual problems","author":"Stewart Smith","date":"2010-09-23","format":false,"excerpt":"Yesterday, I reached a happy milestone in HailDB development. All compiler warnings left in the api\/ directory (the public interface to the database engine) are now either probable\/possible bugs (that we need to look at closely) or are warnings due to unfinished code (that we should finish). There's still a\u2026","rel":"","context":"In &quot;code&quot;","block_context":{"text":"code","link":"https:\/\/www.flamingspork.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/1623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/comments?post=1623"}],"version-history":[{"count":4,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/1623\/revisions"}],"predecessor-version":[{"id":4152,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/1623\/revisions\/4152"}],"wp:attachment":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/media?parent=1623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/categories?post=1623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/tags?post=1623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}