Thread: Passing Bit Fields

  1. #1
    Registered User
    Join Date
    May 2006

    Passing Bit Fields

    Is there a way to return bit fields via class methods? ..Or even typedef them?...Or maybe even (void) pointers to them?

    class BitField
       typedef unsigned:28  Bytes7
       unsigned:28 getBits(){ return bits; }
       unsigned bits:28;
    If nothing else, a native data type 28 bits or larger?
    Last edited by computation; 09-26-2006 at 06:28 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Ask yourself "unsigned what?". Return that.

    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2006
    but int's aren't that big

  4. #4
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Have you considered STL's bitset<N> as a solution?

  5. #5
    Registered User
    Join Date
    May 2003
    Quote Originally Posted by computation
    but int's aren't that big
    A long is guaranteed by the standard to be at least 32 bits.

    Int, in general, will be 32 bits on a 32 bit compiler, and 64 bits on a 64 bit compiler.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Since you can't take the address of bit fields, you can't return a pointer to them. You have to return an instance of the whole enclosing structure or the value of it via an unsigned/signed integer. (Bit fields can only be of type unsigned/unsigned int or signed/int/signed int.)

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bit fields
    By Perspektyva in forum C++ Programming
    Replies: 13
    Last Post: 11-22-2008, 02:38 PM
  2. 64 bit testing
    By DrSnuggles in forum C++ Programming
    Replies: 7
    Last Post: 11-20-2007, 03:20 AM
  3. bit patterns of negtive numbers?
    By chunlee in forum C Programming
    Replies: 4
    Last Post: 11-08-2004, 08:20 AM
  4. Create data type
    By Malefaust in forum C Programming
    Replies: 2
    Last Post: 09-30-2004, 06:06 AM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM