flags

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<T>( this T input, T matchTo ) where T:enum //the constraint I want that doesn't exist in C#3 { return (input & matchTo) != 0; } } So then I could do: MyEnum te...

Enum Flags Attribute

Anyone have a good explanation or example they could post? Edit: I changed the answer, this one is more in depth. ...

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 == FlagTest.Flag1) { // Do something, // however This is never true. } How can I mak...

Most common C# bitwise operations

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; // Set bit 4. or if ((flags == FlagsEnum.Bit4)) == FlagsEnum.Bit4) // Is there a les...

Flags in a database rows, best practices.

I am asking this out of a curiosity. Basically my question is when you have a database which needs a row entry to have things which act like flags, what is the best practice? A good example of this would be the badges on stack overflow, or the operating system field in bugzilla. Any subset of the flags may be set for a given entry. Usua...

How should C bitflag enumerations be translated into C++?

C++ is mostly a superset of C, but not always. In particular, while enumeration values in both C and C++ implicitly convert into int, the reverse isn't true: only in C do ints convert back into enumeration values. Thus, bitflags defined via enumeration declarations don't work correctly. Hence, this is OK in C, but not in C++: typedef en...

object editing and isDirty() flag

Hi all, I'm working on a system were a user can edit existing objects ("Filter" domain objects to be exact) through a GUI. As a UI hint, we only want to enable the save button if the user really modified something to the object. I was wondering if anyone had any experience with this problem and what the best way would be to approach thi...

How do I figure out what -O<num> options do in gcc?

I seem to remember being able to print out (or locate) the specific switches that each -O<num> option turns on. Can you remind? Thanks! ...

Anyone know what an <Optional SQL Explain flag> is?

Does anyone know what an Optional SQL Explain flag is? ...

Autotools : how to set global compilation flag

I have a project with several sources directories : src/A /B /C In each, the Makefile.am contains AM_CXXFLAGS = -fPIC -Wall -Wextra How can avoid repeating this in each source folder ? I tried to modifiy src/Makefile.am and the configure.in, but without success. I thought I could use AC_PROG_CXX to set the compilation fla...

Best practices for bit flags in PHP

I'm writng a small application in PHP + MySQL and have come to the point where there is an object that has a couple (8 so far but not expected to increase) of flags associated with it. The flags are pretty much unrelated although there are some combinations that would make no sense. The object represents a row in a DB (has some methods f...

Setting cmd.exe /V:ON flag without starting new instance

Is there any way to enable execution-time variable expansion for cmd.exe (normally done by typing cmd /V:ON) without starting a new instance of cmd.exe? Similarly, can other settings/flags be changed on the fly? ...

Flags with web services

I have a flag attribute enumeration that is behind a web service as follows: [Serializable,Flags] public enum AccessLevels { None = 0, Read = 1, Write = 2, Full = Read | Write } My problem is the consumer of my web service does not have the original constant values of the enum. The resulting proxy class client side has...

Enum as Flag using, setting and shifting

I have two flags: [Flags] enum Flags { A = 1, B = 2 }; I set them like this: Mode = Flags.A | Flags.B; // default value for(int i = 0; i < args.Length; i++) { switch(args[i]) { case "--a": { if ((Mode & Flags.A) == Flags.A && (Mode & Flags.B) == Flags.B) // both, default assume { Mode = Flags.A; // only A ...

C#: When using RegisterHotKey api call, why does it accept 1, 2, 4, and 8 as modifiers?

I reference to this post; http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html #region fields public static int MOD_ALT = 0x1; public static int MOD_CONTROL = 0x2; public static int MOD_SHIFT = 0x4; public static int MOD_WIN = 0x8; public static int WM_HOTKEY = 0x312; #endregion [DllImport("us...

How to translate the -lXi flag in a linux linker to the appropriate lib?

How does one find out what is the lib that the above flag is referring to? How would I do it for some other one? ...

About assembly conditional code register

suppose we use the addl instruction to perform the equivalent of the C expression "t=a+b",where a,b,t are variables of type int,then the conditional code will be set according to the following C expression: CF: (unsigned t) < (unsigned a) Unsigned Overflow ZF: (t==0) Zero SF: (t<0...

about assembly CF(Carry) and OF(Overflow) flag

It's known that CF indicates unsigned carry out and OF indicates signed overflow. So how does an assembly program differentiate between unsigned and signed data since it's only a sequence of bits? (Through additional memory storage for type information, or through positional information or else?) And could these two flags be used interch...

Is using flags very often in code advisable?

I came across lot of flags while reading someone else code, if (condition1) var1 = true else var1 = false then later, if (var1 == true) // do something. There are lot of flags like this. I eager to know, is using flags very often in code advisable? ...

cl.exe Difference in object files when /E output is the same and flags are the same

Hello: I am using Visual Studio 2005's cl.exe compiler. I call it with a bunch of /I /D and some compilation/optimization flags (example: /Ehsc). I have two compilation scripts, and both differ only in the /I flags (include directories are different). All other flags are the same. These scripts produce different object files (and not j...