Flags, the ambiguity of

This is a discussion on Flags, the ambiguity of within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I just wanted see if i can get input on flags, and how to use them. Basicly I've ...

  1. #1
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704

    Flags, the ambiguity of

    Hey guys, I just wanted see if i can get input on flags, and how to use them.

    Basicly I've been seeing flags in apis(dx especially) And ive been curious exactly how flags work.
    I understand generally you deliminate flags with | ( FLAG_ONE | FLAG_TWO ) .

    The question is, in my function or where ever in my code, how do i find out what the flags are that were passed in?

    Thanks for your time.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    The bar does not delimit the flags. It applies a logical OR to the two values. Look up 'bit manipulation', 'bit shifting', etc...

    int a, b = 1, c = 32;

    a = b|c; //...combine

    //...etc...

    if( a & c ) //...test
    a &= ~c; //...remove

    //...etc, etc.

    The general idea is to use a single variable to store many 'settings', thus saving space. That is, since, say, an unsigned integer has 32 bits (on most machines), we could conserve memory by placing boolean values into each bit position. Testing a certain bit tells us if that flag is set or not.

    For instance, the answers to a true/false quiz of 96 questions could be stored on 3 unsigned ints, etc.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. obtaining which combination of flags are being set
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 07-16-2008, 03:43 AM
  2. Cannot get interface flags: Invalid argument
    By nasim751 in forum C Programming
    Replies: 1
    Last Post: 04-15-2008, 03:27 AM
  3. Cannot get interface flags: Invalid argument
    By nasim751 in forum C Programming
    Replies: 3
    Last Post: 04-14-2008, 03:29 AM
  4. Using 'flags'
    By cyreon in forum C++ Programming
    Replies: 11
    Last Post: 01-28-2008, 04:21 PM
  5. Bit Flags
    By Padawan in forum C Programming
    Replies: 15
    Last Post: 03-30-2004, 10:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21