{"id":1809,"date":"2014-01-29T15:04:27","date_gmt":"2014-01-29T20:04:27","guid":{"rendered":"http:\/\/bitpost.com\/news\/?p=1809"},"modified":"2014-01-29T15:08:24","modified_gmt":"2014-01-29T20:08:24","slug":"using-correct-c11-integer-types","status":"publish","type":"post","link":"https:\/\/bitpost.com\/news\/2014\/using-correct-c11-integer-types\/","title":{"rendered":"Using correct C++11 integer types"},"content":{"rendered":"<p>I really like the &#8220;fast&#8221; C++11 types, that give best performance for a guaranteed minimum bit width.  Use them when you know a variable will not exceed the maximum value of that bit width, but does not have to be a precise bit width in memory or elsewhere.<\/p>\n<p>Pick specific-width fields whenever data is shared with other processes and components and you want a guarantee of its bit width.<\/p>\n<p>And when using pointer size and array indices you should use types defined for those specific situations.<\/p>\n<p>FAST types:<\/p>\n<pre><code>\r\n    int_fast8_t\r\n    int_fast16_t                fastest signed integer type with width of\r\n    int_fast32_t                at least 8, 16, 32 and 64 bits respectively\r\n    int_fast64_t\r\n\r\n    uint_fast8_t\r\n    uint_fast16_t               fastest unsigned integer type with width of\r\n    uint_fast32_t               at least 8, 16, 32 and 64 bits respectively\r\n    uint_fast64_t\r\n<\/code><\/pre>\n<p>SMALL types:<\/p>\n<pre><code>\r\n    int_least8_t\r\n    int_least16_t               smallest signed integer type with width of\r\n    int_least32_t               at least 8, 16, 32 and 64 bits respectively\r\n    int_least64_t\r\n\r\n    uint_least8_t\r\n    uint_least16_t\t\tsmallest unsigned integer type with width of\r\n    uint_least32_t\t\tat least 8, 16, 32 and 64 bits respectively\r\n    uint_least64_t\r\n<\/code><\/pre>\n<p>EXACT types:<\/p>\n<pre><code>\r\n    int8_t                      signed integer type with width of\r\n    int16_t                     exactly 8, 16, 32 and 64 bits respectively\r\n    int32_t                     with no padding bits and using 2's complement for negative values\r\n    int64_t                     (provided only if the implementation directly supports the type)\r\n\r\n    uint8_t                     unsigned integer type with width of\r\n    uint16_t                    exactly 8, 16, 32 and 64 bits respectively\r\n    uint32_t                    (provided only if the implementation directly supports the type)\r\n    uint64_t\r\n<\/code><\/pre>\n<p>SPECIFIC-USE types:<\/p>\n<pre><code>\r\n    intptr_t                    integer type capable of holding a pointer\r\n    uintptr_t                   unsigned integer type capable of holding a pointer \r\n    size_t                      unsigned integer type capable of holding an array index (same size as uintptr_t)\r\n<\/code><\/pre>\n<p>Pretty much SAY BYE BYE TO [int]!  \ud83d\ude42  &#8230;or when going across OSes and 32\/64bit platforms you will be playing with this matrix of fun (originally from <a href=\"http:\/\/www.viva64.com\/en\/a\/0050\/\">here<\/a>):<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/bitpost.com\/news\/wp-content\/uploads\/image2.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1811\" data-permalink=\"https:\/\/bitpost.com\/news\/2014\/using-correct-c11-integer-types\/image2\/\" data-orig-file=\"https:\/\/i0.wp.com\/bitpost.com\/news\/wp-content\/uploads\/image2.png?fit=842%2C393&amp;ssl=1\" data-orig-size=\"842,393\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"image2\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/bitpost.com\/news\/wp-content\/uploads\/image2.png?fit=300%2C140&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/bitpost.com\/news\/wp-content\/uploads\/image2.png?fit=842%2C393&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/bitpost.com\/news\/wp-content\/uploads\/image2.png?resize=842%2C393\" alt=\"image2\" width=\"842\" height=\"393\" class=\"aligncenter size-full wp-image-1811\" srcset=\"https:\/\/i0.wp.com\/bitpost.com\/news\/wp-content\/uploads\/image2.png?w=842&amp;ssl=1 842w, https:\/\/i0.wp.com\/bitpost.com\/news\/wp-content\/uploads\/image2.png?resize=300%2C140&amp;ssl=1 300w\" sizes=\"auto, (max-width: 842px) 100vw, 842px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I really like the &#8220;fast&#8221; C++11 types, that give best performance for a guaranteed minimum bit width. Use them when you know a variable will not exceed the maximum value of that bit width, but does not have to be a precise bit width in memory or elsewhere. Pick specific-width fields whenever data is shared [&hellip;]<\/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,"enabled":false},"version":2}},"categories":[22,2],"tags":[190,119],"class_list":["post-1809","post","type-post","status-publish","format-standard","hentry","category-cpp","category-chatter","tag-c11","tag-cross-platform"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9M11L-tb","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts\/1809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/comments?post=1809"}],"version-history":[{"count":4,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts\/1809\/revisions"}],"predecessor-version":[{"id":1814,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts\/1809\/revisions\/1814"}],"wp:attachment":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/media?parent=1809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/categories?post=1809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/tags?post=1809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}