Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Why does struct user_settings use ints when chars would do?
From: TP Diffenbach (rockbox_at_diffenbach.org)
Date: 2003-05-06


There are a number of values in struct user_settings, e.g,
    
    int peak_meter_release; /* units per read out */
    int peak_meter_hold; /* hold time for peak meter in 1/100 s */
    int peak_meter_clip_hold; /* hold time for clips */
    /* . . . */
    int bidir_limit; /* bidir scroll length limit */
    int scroll_delay; /* delay (in 1/10s) before starting scroll */
    int scroll_step; /* pixels to advance per update */

which have type int, but which have ranges smaller than int. In fact, these values are saved to the config_block in chars, or masked parts of chars:

    config_block[0xb5]=(unsigned char)global_settings.scroll_step;
    config_block[0xb6]=(unsigned char)global_settings.scroll_delay;
    config_block[0xb7]=(unsigned char)global_settings.bidir_limit;
    /* . . . */
    config_block[0x1c] = (unsigned char)global_settings.peak_meter_hold |
        (global_settings.rec_editable?0x80:0);
    /* . . . */
    config_block[0xb0] = (unsigned char)global_settings.peak_meter_clip_hold |
        (global_settings.peak_meter_performance ? 0x80 : 0);
    config_block[0xb1] = global_settings.peak_meter_release |
        (global_settings.peak_meter_dbfs ? 0x80 : 0);
        
So if these variables all hold values in the range of unsigned char (or less), why are they taking up sizeof( int ) bits?
    
The only thing I can think of is perhaps to avoid the runtime cost of integral promotion when operations are performed on these values? Is integral promotion that costly?? Or an I misisng some more subtle reason?

Thanks,
Tom

-- 
Archos FM has a Rockbox!



Page was last modified "Jan 10 2012" The Rockbox Crew
aaa