LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-29-2004, 08:30 AM   #1
feetyouwell
Member
 
Registered: Dec 2003
Location: NC, US
Distribution: Novell Linux Eval (2.6.5)
Posts: 240

Rep: Reputation: 30
general programming in c: what is a flag


I heard people use this term many time but I am still not quite sure what exactly a flag is in c, is it like a boolean value? Can someone give me good explaination or direct me to some websites that do? thanks.
 
Old 09-29-2004, 08:42 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you are inside the C code, then yes, it's generally a boolean concept, implemented as an int. However, it's possible for a flag to have as many values as you need...
Some people do also apply the term to a cmd line option that takes no value ie it's either specified or not.
 
Old 09-29-2004, 09:41 AM   #3
gsu_790
LQ Newbie
 
Registered: Sep 2004
Location: India
Distribution: FC 2
Posts: 3

Rep: Reputation: 0
A flag is nothing but a status indicator. Any variable can be used as a flag. Boolean vars are usually used for flags since they take only one bit space and can be used to check an 'ON/OFF' condition.
Like for instance, you add a couple of numbers, and if the result is negative, then you can set a flag to 1. If the sum is positive, set it to 0. Now, elsewhere you can check the status of this addition by looking at the value of the flag var. <Elementary concept, used very often>

<gave you this eg, since there is a signed bit flag [register] in all processors which does the above operation.>

suresh
 
Old 09-29-2004, 05:05 PM   #4
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 48
To the above I'd add that you can also have an int, used for a bunch of flags, using the bitwise operators. see Bitwise manipulations.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
General thoughts on programming IDEs? Gurduloo Linux - General 4 06-03-2005 11:23 AM
good general programming forum? dr_zayus69 Programming 1 05-21-2005 05:36 AM
Use Of Secure_no_root Flag mulholland Linux - Security 0 01-12-2005 03:19 AM
Red Flag varun_33 Linux - Distributions 1 01-11-2005 02:38 PM
bootable flag? alaios Debian 1 04-29-2004 11:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration