dev builds
themes manual
device status forums
mailing lists
IRC bugs
dev guide

Rockbox mail archive

Subject: Why does struct user_settings use ints when chars would do?

Why does struct user_settings use ints when chars would do?

From: TP Diffenbach <>
Date: Mon, 5 May 2003 23:16:16 -0400

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 |
    /* . . . */
    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?


Archos FM has a Rockbox!
Received on 2003-05-06

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy