flags

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

浪尽此生 提交于 2019-12-19 09:47:04
问题 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 enum Foo { Foo_First = 1<<0, Foo_Second = 1<<1, } Foo; int main(void) { Foo x = Foo_First | Foo_Second; // error in C++ return 0; } How should this problem be

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

给你一囗甜甜゛ 提交于 2019-12-19 09:46:17
问题 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 enum Foo { Foo_First = 1<<0, Foo_Second = 1<<1, } Foo; int main(void) { Foo x = Foo_First | Foo_Second; // error in C++ return 0; } How should this problem be

Why does Java use -D to indicate system properties?

那年仲夏 提交于 2019-12-19 05:17:22
问题 Why is the flag that indicates a System property in Java -D ? Surely there is some semantics to this letter choice, but I can't guess what it is. 回答1: It is short for setting a system define. "define" debug to yes -Ddebug=yes There is some historical context, as other compilers use similar flags. For example, gcc uses -D to set a preprocessor define. gcc -D debug=yes test.c will compile test.c with a preprocessing environment where the preprocessor variable debug is set to yes . 回答2: "defines

Autotools : how to set global compilation flag

走远了吗. 提交于 2019-12-18 12:18:24
问题 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 flags globally but can't find much documentation on how to use those macro (do you have any pointer to such a documentation ?). Thanks in advance 回答1: You can do several things:

What does regex' flag 'y' do?

大憨熊 提交于 2019-12-18 11:41:33
问题 MDN says: To perform a "sticky" search, that matches starting at the current position in the target string, use the y flag. I don't quite understand it. 回答1: Regular expression objects have a lastIndex property, which is used in different ways depending on the g (global) and y (sticky) flags. The y (sticky) flag tells the regular expression to look for a match at lastIndex and only at lastIndex (not earlier or later in the string). Examples are worth 1024 words: var str = "a0bc1"; // Indexes:

how to set boolean flag of thread-1 from thread-2 in Java multithreading

↘锁芯ラ 提交于 2019-12-18 09:47:35
问题 I am writing a simple multithreaded application that involves three threads: Thread-1 , Thread-2 and main . Thread-1 is a random number generator class that produces random doubles and feeds to Thread-2 . Thread-2 consumes the numbers to calculate the average .I have used PipedOutputStream that Thread-1 feeds with random numbers . Thread-2 uses PipedInputStream to eat up the random numbers . The question is:: if the average exceeds 1E5 in Thread-2 , I want to signal Thread-1 to stop producing

What Does the [Flags] Attribute Really Do?

南笙酒味 提交于 2019-12-17 16:27:03
问题 What does applying [Flags] really do? I know it modifies the behavior of Enum.ToString, but does it do anything else? (e.g. Different compiler or runtime behavior, etc.) Edit : Yeah, I'm aware that it documents the fact that the enum is intended to be used as bitwise flags, and that it's more logical to apply it to bit flags. I was asking more about concrete behavior changes though, not general programming practices. 回答1: From an MSDN article: It is interesting to note that when Flags is

WS_EX_TRANSPARENT - What does it actually do?

扶醉桌前 提交于 2019-12-17 13:27:22
问题 In my project, I create a form with the opacity controlled by the user. If the form was fully transparent the mouse events 'fell through' (without my intervention), otherwise my form handled them. After reading this question and overriding the CreateParams property to set the WS_EX_TRANSPARENT flag on my form, it now allows mouse events to fall through when the opacity is any value <255. This is exactly what I want, but it concerns me that I don't understand why it works. From what I've read,

PHP function flags, how?

扶醉桌前 提交于 2019-12-17 06:41:40
问题 I'm attempting to create a function with flags as its arguments but the output is always different with what's expected : define("FLAG_A", 1); define("FLAG_B", 4); define("FLAG_C", 7); function test_flags($flags) { if($flags & FLAG_A) echo "A"; if($flags & FLAG_B) echo "B"; if($flags & FLAG_C) echo "C"; } test_flags(FLAG_B | FLAG_C); # Output is always ABC, not BC How can I fix this problem? 回答1: Flags must be powers of 2 in order to bitwise-or together properly. define("FLAG_A", 0x1); define

Compiling C++11 with g++

我怕爱的太早我们不能终老 提交于 2019-12-16 20:33:32
问题 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 12.04.) Here is the error that I get from the compiler when I attempt to use a library which is included in C++11 (i.e. array): #include <array> #include <iostream> int main() { std::array<int, 3> arr = {2, 3, 5}; ... } This file requires compiler and