Questions tagged [flags]

Flags are atomic data structures used to identify state in a program.

A flag field is an integer interpreted as a sequence of boolean bits, each called a flag. A single flag has two possible states: 0, representing false or off, and 1, representing true or on.

This tag can be used for problems related to .

Source

Wikipedia

1473 questions
1720
votes
14 answers

What does the [Flags] Enum Attribute mean in C#?

From time to time I see an enum like the following: [Flags] public enum Options { None = 0, Option1 = 1, Option2 = 2, Option3 = 4, Option4 = 8 } I don't understand what exactly the [Flags] attribute does. Anyone have a good…
Brian Leahy
  • 34,677
  • 12
  • 45
  • 60
824
votes
17 answers

How to see normal print output created during pytest run?

Sometimes I want to just insert some print statements in my code, and see what gets printed out when I exercise it. My usual way to "exercise" it is with existing pytest tests. But when I run these, I don't seem able to see any standard output (at…
Des
  • 9,195
  • 4
  • 18
  • 21
425
votes
6 answers

Compiling C++11 with g++

I'm trying to update my C++ compiler to C++11. I have searched a bit and I have come to the conclusion that I have to use the flag -std=c++0x or -std=gnu++0x, but I don't know many things about flags. Can anyone help me? (I'm using Ubuntu…
Rontogiannis Aristofanis
  • 8,883
  • 8
  • 41
  • 58
228
votes
18 answers

How to check if any flags of a flag combination are set?

Let's say I have this enum: [Flags] enum Letters { A = 1, B = 2, C = 4, AB = A | B, All = A | B | C, } To check if for example AB is set I can do this: if((letter & Letters.AB) == Letters.AB) Is there a simpler way to…
Svish
  • 152,914
  • 173
  • 462
  • 620
218
votes
11 answers

Most common C# bitwise operations on enums

For the life of me, I can't remember how to set, delete, toggle or test a bit in a bitfield. Either I'm unsure or I mix them up because I rarely need these. So a "bit-cheat-sheet" would be nice to have. For example: flags = flags | FlagsEnum.Bit4; …
steffenj
  • 7,967
  • 10
  • 35
  • 41
218
votes
4 answers

Bash if statement with multiple conditions throws an error

I'm trying to write a script that will check two error flags, and in case one flag (or both) are changed it'll echo-- error happened. My script: my_error_flag=0 my_error_flag_o=0 do something..... if [[ "$my_error_flag"=="1" ||…
Simply_me
  • 2,840
  • 4
  • 19
  • 27
174
votes
3 answers

How can I remove a flag in C?

There is a variable that holds some flags and I want to remove one of them. But I don't know how to remove it. Here is how I set the flag. my.emask |= ENABLE_SHOOT;
Aaron de Windt
  • 16,794
  • 13
  • 47
  • 62
165
votes
7 answers

Why do enum permissions often have 0, 1, 2, 4 values?

Why are people always using enum values like 0, 1, 2, 4, 8 and not 0, 1, 2, 3, 4? Has this something to do with bit operations, etc.? I would really appreciate a small sample snippet on how this is used correctly :) [Flags] public enum…
Pascal
  • 12,265
  • 25
  • 103
  • 195
162
votes
11 answers

How to Compare Flags in C#?

I have a flag enum below. [Flags] public enum FlagTest { None = 0x0, Flag1 = 0x1, Flag2 = 0x2, Flag3 = 0x4 } I cannot make the if statement evaluate to true. FlagTest testItem = FlagTest.Flag1 | FlagTest.Flag2; if (testItem ==…
David Basarab
  • 72,212
  • 42
  • 129
  • 156
131
votes
4 answers

Perl flags -pe, -pi, -p, -w, -d, -i, -t?

I have seen lots of ways of running Perl code or scripts, with different flags. However, when I try to google for what each flag means, I mainly get results to generic Perl sites and no specific information regarding the flags or their use is found…
Tudor Constantin
  • 26,330
  • 7
  • 49
  • 72
117
votes
2 answers

Print All JVM Flags

Found an interesting JVM Flag : java -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal -version It prints hundreds of various options, I never heard about before. It also prints default values, that helps diagnose JVM behaviors better. Another…
Sachin Bhansali
  • 1,372
  • 2
  • 9
  • 12
104
votes
2 answers

How is -march different from -mtune?

I tried to scrub the GCC man page for this, but still don't get it, really. What's the difference between -march and -mtune? When does one use just -march, vs. both? Is it ever possible to just -mtune?
Jameson
  • 6,400
  • 6
  • 32
  • 53
96
votes
12 answers

Anyone know a good workaround for the lack of an enum generic constraint?

What I want to do is something like this: I have enums with combined flagged values. public static class EnumExtension { public static bool IsSet( this T input, T matchTo ) where T:enum //the constraint I want that doesn't exist in…
Keith
  • 150,284
  • 78
  • 298
  • 434
82
votes
3 answers

Start new Activity and finish current one in Android?

Currently I'm starting a new Activity and calling finish on a current one. Is there any flag that can be passed to Intent that enables finishing current Activity without a need to call finish manually from code?
pixel
  • 24,905
  • 36
  • 149
  • 251
77
votes
4 answers

Disable keep screen on

I used: getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); How do I resume to Default state (no-keep-on)?
OkyDokyman
  • 3,786
  • 7
  • 38
  • 50
1
2 3
98 99