Thread: How do I force my compiler to access HW registers as 32 bit instead of bytes?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    14
    Quote Originally Posted by tabstop View Post
    Unionizing the bitfields requires 32 bits of space. A register variable and using bitmasks requires 32 bits of space (unless you want to store the values separately from the register-as-a-whole, then that would take 64 bits).

    I have never used "union" before. What will union do to the struct?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by samdomville View Post
    I have never used "union" before. What will union do to the struct?
    Nothing.

    union just overlays two variables into the same memory location (broadly speaking). So you would have a union with an int and your struct, and each of them would use the same 32 bits of memory. (But reading/writing the int would force the compiler to read all 32 bits, instead of just 8 sometimes.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Replies: 7
    Last Post: 12-10-2004, 08:18 AM
  3. question about 32 bit addresses??
    By newbie02 in forum C++ Programming
    Replies: 3
    Last Post: 09-12-2003, 02:02 PM
  4. 16 bit or 32 bit
    By Juganoo in forum C Programming
    Replies: 9
    Last Post: 12-19-2002, 07:24 AM