Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 5th, 2008, 9:08 PM   #1
musica07
Newbie
 
Join Date: Jun 2008
Posts: 11
Rep Power: 0 musica07 is on a distinguished road
Post Flags in Programming

Hello.

I would like to know what do flags contribute in C programming. What it is actually for?

Thanks(:
musica07 is offline   Reply With Quote
Old Jun 5th, 2008, 9:27 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 843
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Flags in Programming

Assuming you are referring to bitwise operators, there was a recent discussion on this topic.
titaniumdecoy is offline   Reply With Quote
Old Jun 5th, 2008, 9:47 PM   #3
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3 Jimbo is on a distinguished road
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>
Jimbo is offline   Reply With Quote
Old Jun 6th, 2008, 10:14 AM   #4
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5 lectricpharaoh will become famous soon enough
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
lectricpharaoh is offline   Reply With Quote
Old Jun 7th, 2008, 3:52 AM   #5
musica07
Newbie
 
Join Date: Jun 2008
Posts: 11
Rep Power: 0 musica07 is on a distinguished road
Re: Flags in Programming

Okie. Thanks guys(:
musica07 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC