c - Fixed width, minimum width and fastest minimum width unsigned 8 bit integer -


three days read article on choosing correct integer size. before reading article, unaware of these 3 keywords viz:

1) fixed width unsigned 8-bit integer: uint8_t. (typedef's c99 complaints)

2) minimum width unsigned 8-bit integer: uint_least8_t.

3) fastest minimum width unsigned 8-bit integer: uint_fast8_t.

so question are:

1) mean saying "at least 8 bits wide" uint_least8_t & uint_fast8_t. example, let's take @ snippet of code

for(u16 i=0;i<counter;i++) {   increment_counter++; } 

here :- u16 means unsigned short. counter , increment_counter 2 variables

when counter =0xff; increment_counter work fine type of keyword declaration. when counter =0x01ff; kind of declaration should choose? uint_least8_t (who guaranteed @ least 8 bits wide) or unit16 type?

2) how choosing uint_fast8_t affects code speed.

3) how choosing uint_least8_t consumes lesser data memory unsigned char.

i webbed doubts got nothing. appreciated.

thanks in advance

1) mean saying "at least 8 bits wide"

it means compiler map type appropriate target, guarantee have type it's @ least 8 bits. concern should not limited question of "what type should make index guards postincrement" -- should focus on sane usage within 8 bits.

so, yes, on lookout overflow think hard whether makes sense design. have user-input, example? or counting static elements of design, perhaps? let's uint_fast8_t framistan_modules declared count number of "framistan" functions. have defined 3 , can't imagine why you'd ever need more 5.

2) how choosing uint_fast8_t affects code speed.

it's difficult code speed without empirical metrics. idea behind type compiler might choose register-width type uint_fast8_t, if registers larger 8 bits.

3) how choosing uint_least8_t consumes lesser data memory unsigned char.

this unlikely case impossible. however, it's similar _fast8_t in you're giving compiler degree of freedom (not merely 8 bits). difference here you're not optimizing speed in fast, there may different balance between register width , other.


in general, if you've gotten far enough asking these questions, gain witnessing different code that's generated in these conditions. , in likelyhood you'd served measuring performance , memory consumption each.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -