macros

Undefined reference to vtable… Q_OBJECT macro [duplicate]

不打扰是莪最后的温柔 提交于 2020-02-16 06:23:26
问题 This question already has answers here : Qt Linker Error: “undefined reference to vtable” [duplicate] (9 answers) Closed 6 years ago . When I uncomment the Q_OBJECT macro that I need for signal-slot I get a undefined reference to vtable for MyApp error, but without the macro it compiles perfectly but I can't use signals and slots without it. I think I may be doing something stupid wrong, but please try helping because I realy can't find the problem. O and I know my code is untidy and am

Undefined reference to vtable… Q_OBJECT macro [duplicate]

拟墨画扇 提交于 2020-02-16 06:22:14
问题 This question already has answers here : Qt Linker Error: “undefined reference to vtable” [duplicate] (9 answers) Closed 6 years ago . When I uncomment the Q_OBJECT macro that I need for signal-slot I get a undefined reference to vtable for MyApp error, but without the macro it compiles perfectly but I can't use signals and slots without it. I think I may be doing something stupid wrong, but please try helping because I realy can't find the problem. O and I know my code is untidy and am

Cmake global variable in macro scope

萝らか妹 提交于 2020-02-15 23:55:49
问题 I'm trying to create a global list and I want it appended in a macro. Here is my setup: project \__. CMakeLists.txt \__. level1 \__. CMakeLists.txt \__. level2a \__. CMakeLists.txt \__. level2b \__. CMakeLists.txt Here is my top level CMakeLists.txt : cmake_minimum_required(VERSION 2.8) macro(listappend var) list(APPEND MY_GLOBAL_LIST "${var}") message(STATUS "LIST IN MACRO SCOPE: ${MY_GLOBAL_LIST}") endmacro(listappend) set(MY_GLOBAL_LIST "") add_subdirectory(level1) message(STATUS "LIST: $

Macro expansion in C++

断了今生、忘了曾经 提交于 2020-02-15 10:01:34
问题 How can I define a macro (or a workaround for this) where the parameter is at the beginning of the line? #define SINGLETON_IMPLEMENTATION(className) \ ##className* ##className::instance_ = NULL; This give a compiler warning (GCC 3.2.3): " '##' cannot appear at either end of a macro expansion" 回答1: ## is the concatenation operator; the compiler is just complaining about that. You cannot concatenate a token without something before it, i.e. at the beginning of the macro expansion; just try to

Strange behavior of Macro-expansion

≡放荡痞女 提交于 2020-02-10 16:01:46
问题 Here's the code: #include <stdio.h> #include <stdio.h> #define VAL1(a,b) a*b #define VAL2(a,b) a/b #define VAL3(a,b) ++a%b int main() { int a = 1; int b = 2; int c = 3; int d = 3; int e = 5; int result = VAL2(a,d)/VAL1(e,b)+VAL3(c,d); // result = 1 //int result = a/d/e*b+++c%d; // result = 0 printf("%d\n", result); return 0; } Why aren't the results of two statements the same? 回答1: In one case you have + ++ and in the other case you have ++ + . + ++ and ++ + are different streams of tokens .

Strange behavior of Macro-expansion

半城伤御伤魂 提交于 2020-02-10 15:58:46
问题 Here's the code: #include <stdio.h> #include <stdio.h> #define VAL1(a,b) a*b #define VAL2(a,b) a/b #define VAL3(a,b) ++a%b int main() { int a = 1; int b = 2; int c = 3; int d = 3; int e = 5; int result = VAL2(a,d)/VAL1(e,b)+VAL3(c,d); // result = 1 //int result = a/d/e*b+++c%d; // result = 0 printf("%d\n", result); return 0; } Why aren't the results of two statements the same? 回答1: In one case you have + ++ and in the other case you have ++ + . + ++ and ++ + are different streams of tokens .

Comma in C/C++ macro passed to another macro

无人久伴 提交于 2020-02-04 04:43:10
问题 I have these macros which generate error in Visual Studio 2015. #define log_params __FILE__, __LINE__ #define log(file, line, message, ...) _snprintf_s(nullptr, 0, 0, message, __VA_ARGS__) Now calling this never works log(log_params, "testing %d", 4) Any thoughts? I also checked output of preprocessor and it is: _snprintf_s(nullptr, 0, 0, 4 ); EDIT 1 Intresting finding #define log(file, line, message, ...) file line will produce this : "service.cpp", 164 "testing %d" Is it normal? 回答1: The

When can I be sure a constexpr global variable will be “forgotten”, like a C macro?

亡梦爱人 提交于 2020-02-02 12:24:26
问题 I want to use a global constexpr variable: constexpr int foo = 123; instead of a C macro: #define FOO (123) in some code I'm writing. I would like to be guaranteed the same behavior, in the sense that this will not take up space in memory at runtime, nor will it be visible/exist in the compiled object code (that is, its value will be used as an immediate where relevant). Can I get this guarantee at all? Under some conditions? Assume, of course, I'm not trying to use x's address or any such

C/C++ Can “for loop” be used in a marco instead of “do while”?

試著忘記壹切 提交于 2020-02-02 11:13:25
问题 Are the two below constructions equivalent in assumption that "cond" is not conflicting with any name in the program #define DOWHILE do { (some_code); } while (0) #define FORLOOP for(bool cond = true; cond; cond = false) (some_code) The purpose of this question is: I have something like this bool printLogs; // nonconstant dynamic variable And I have a macro(I cannot do big changes, it is a big project; I have to deal with this macro) #define LOG ... which is used like LOG << "message" << 1 <<

use a macro to show the stringified content of a macro

守給你的承諾、 提交于 2020-01-30 11:56:07
问题 I am writing code for an Arduino. The code starts to get long so I want to use some debugging macros, and to be able to show some debugging information on serial port. For example, I have some macros to define which serial ports I use: #define SERIAL_GPS Serial1 #define SERIAL_IRIDIUM Serial2 #define SERIAL_VN100 Serial3 How can I write a macro to show the ports I use for each one? I.e. some macro that would print on a debug serial port: Port for GPS: Serial1 Port for Iridium: Serial2 Port