![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2008
Posts: 11
Rep Power: 0
![]() |
Hello.
I would like to know what do flags contribute in C programming. What it is actually for? Thanks(: |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Re: Flags in Programming
Assuming you are referring to bitwise operators, there was a recent discussion on this topic.
|
|
|
|
|
|
#3 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3
![]() |
Re: Flags in Programming
As a quick summary (which was implied but not directly said in the other thread), flags are often used as a way of taking a bunch of boolean values and compressing them into a single integer-type variable. Then, the bitwise operators discussed in the linked thread are used to make it easier to read the now-compressed boolean values back out.
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#4 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5
![]() |
Re: Flags in Programming
A more general answer is that a flag is a variable (usually boolean, ie having only two values like true/false, off/on, yes/no, etc) that indicates some program state.
For example, say you have a program that displays a window with a status bar at the bottom, but the user can turn off the display of the status bar. You might represent this in code with a boolean variable called statusBarVisible, with true indicating it's visible, and false indicating it's not.Flags are also often used in loops. Say you have a loop that receives input from the user. You could have a flag indicating whether or not the input is valid; assume false means bad input. Set the flag to true at the beginning of the loop, get the input, and set the flag to false if you detect it's bad at any stage. Then before you process it, you can simply check the state of the flag to see if the input is valid or not. Since the flag is set on each loop iteration, it allows you to check this for each item input by the user, and it's cleaner than having a mess of nested if statements.One last note: you might see references to 'setting' and 'clearing' flags. Unless it says 'set to false', 'set to zero', or something similar, the term 'set' refers to giving the flag a value of true, one, on, etc, and 'clear' means the opposite.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jun 2008
Posts: 11
Rep Power: 0
![]() |
Re: Flags in Programming
Okie. Thanks guys(:
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming with Java: Tutorial | ReggaetonKing | Java | 7 | May 20th, 2008 10:58 AM |
| Programming without post secondary education | Eric the Red | Other Programming Languages | 6 | Mar 7th, 2006 5:56 PM |
| Does Programming Make You Smarter? | Sane | Coder's Corner Lounge | 43 | Oct 2nd, 2005 6:12 AM |
| MIT's Metaphor For Software Programming | Infinite Recursion | Other Programming Languages | 2 | Jun 12th, 2005 6:42 AM |