Thread: Bit Packing Issue

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404

    Bit Packing Issue

    I've tried searching for this but I can't find a specific thread about what I'm seeing.

    Code:
    //FLAC METADATA_BLOCK_STREAMINFO
    struct streaminfo {
    	uint16_t min_block_size:16;    //16 bits, 0 bits left
    	uint16_t max_block_size:16;    //32 bits, 0 bits left
    	uint32_t min_frame_size:24;    //64 bits, 8 bits left
    	uint32_t max_frame_size:24;    //96 bits, 16 bits left
    	uint32_t sample_rate:20;       //128 bits, 28 bits left
    	uint32_t num_channels:3;       //128 bits, 25 bits left
    	uint32_t bits_per_sample:5;    //128 bits, 20 bits left
    	uint64_t total_samples:36;     //192 bits, 48 bits left
    	uint32_t md5_sig1:32;          //Why doesn't this fit in the 192?
    	//uint16_t md5_sig2:16;
    } __attribute__ ((packed));
    Have I done my math right? Shouldn't that fit in the remainder of the allocated bits? I'm doing a sizeof() on my system and I'm getting 28 bytes (224 bits).

    FYI I'm using gcc 4.8.0 (mingw32).

    Thanks!

    Edit: Should alignment be a concern? 192 bits (24 bytes) is divisible by 4 bytes, which I think is the default alignment.
    Last edited by carrotcake1029; 05-18-2013 at 03:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. First fit bin packing help?
    By wazz in forum C Programming
    Replies: 3
    Last Post: 10-15-2009, 06:58 PM
  2. Packing a struct
    By XSquared in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2006, 12:49 AM
  3. GTK+ packing widgets..
    By BobS0327 in forum Linux Programming
    Replies: 2
    Last Post: 04-26-2006, 10:18 AM
  4. packing an integer?
    By yahn in forum C++ Programming
    Replies: 5
    Last Post: 01-01-2006, 05:50 PM
  5. help with packing
    By soonerfan in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 05:59 PM