c-preprocessor

QT5 migration and Boost: if.hpp: Macro argument mismatch bug

*爱你&永不变心* 提交于 2019-12-05 20:54:05
问题 In qt 4.8 I used boost (1.52) It all was ok... Now I try to move to QT5 and get if.hpp: Macro argument mismatch error on line 131 BOOST_MPL_AUX_NA_SPEC(3, if_) . In some QT forums there is presented a solution like this: #ifndef Q_MOC_RUN // All boost includes #endif // Q_MOC_RUN in each my file that uses boost... So question here is - how to tell to boost that QT is not ready for BOOST_MPL_AUX_NA_SPEC and that boost shall use some more primitive preprocessor syntax one that would be QT5

#if TRUE vs #if YES vs #if 1 are different in Objective-C?

≯℡__Kan透↙ 提交于 2019-12-05 20:00:23
In Xcode 6.1.1 (Obj-C) #if 1 NSLog(@"print 1"); #endif #if TRUE NSLog(@"print TRUE"); #endif #if YES NSLog(@"print YES"); #endif And the result: print 1 print TRUE Can explain to me the result ? Why #if TRUE vs #if YES vs #if 1 are different? Mhm... I`m not really an objective-c person, I personally like c++ better, but let me try to answer you anyways. if 1 The compiler, in the end of it, like pretty much everything in computers, runs on zeros and ones. When you write an "if 1" statement in your code, it will always do it, like every other number you might put there - that is, except zero.

What preprocessor define does -fopenmp provide?

感情迁移 提交于 2019-12-05 18:27:50
I've got some code that can run with (or without) OpenMP - it depends on how the user sets up the makefile. If they want to run with OpenMP, then they just add -fopenmp to CFLAGS and CXXFLAGS . I'm trying to determine what preprocessor macro I can use to tell when -fopenmp is in effect. The omp.h header does not look very interesting: $ cat /usr/lib/gcc/x86_64-linux-gnu/4.8/include/omp.h | grep define #define OMP_H 1 #define _LIBGOMP_OMP_LOCK_DEFINED 1 # define __GOMP_NOTHROW throw () # define __GOMP_NOTHROW __attribute__((__nothrow__)) And I can't get the preprocessor to offer up anything

Remove the comments generated by cpp

笑着哭i 提交于 2019-12-05 18:17:42
I use #include ".../frontend/tokens.mll" in lexer.mll , and then cpp -C -P frontend/lexer.mll -o frontend/lexer_new.mll to generate lexer_new.mll . That worked until I upgraded my ubuntu from 12.04 to 14.04 yesterday. The compilation gives an error: ocamllex frontend/lexer_new.mll File "frontend/lexer_new.mll", line 1, character 1: illegal character /. make: *** [frontend/lexer_new.ml] Error 3 That is because in lexer_new.mll several lines of C comments have been inserted in the beginning: /* Copyright (C) 1991-2014 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU

What's the difference in practice between inline and #define?

旧时模样 提交于 2019-12-05 18:04:23
问题 As the title says; what's the difference in practice between the inline keyword and the #define preprocessor directive? 回答1: #define is a preprocessor tool and has macro semantics. Consider this, if max(a,b) is a macro defined as #define max(a,b) ((a)>(b)?(a):(b)) : Ex 1: val = max(100, GetBloodSample(BS_LDL)) would spill extra innocent blood, because the function will actually be called twice. This might mean significant performance difference for real applications. Ex 2: val = max(3,

Using the C preprocessor to generate function declarations

折月煮酒 提交于 2019-12-05 16:48:04
I have a lot of functions to declare in this format: int foo_100(int, int); int foo_200(int, int); int foo_300(int, int); int foo_400(int, int); typedef int (*foo)(int, int); struct foo foo_library[] = { foo_100, foo_200, foo_300, foo_400 }; Is there a way I can use the C preprocessor to partially automate this task? Ideally, something like this: foo.txt 100 200 300 400 foo.h typedef int (*foo)(int, int); #define DEFINE_FOO(id_) int foo_##id_(int, int); DEFINE_FOO(#include"foo.txt") struct foo foo_library[] = { #include "foo.txt" }; You could use the X macro trick: // foo_list.h #define MY

How to write safe and user friendly c/c++ #define macros

孤者浪人 提交于 2019-12-05 16:42:43
I have been thinking about how macros can be written to be safe, readable and intuitive. Proper use of them should be understood by the looks of them and when used incorrectly the compiler should tell you, and not let you introduce an obscure bug. When writing multiple line define macros I usually find myself constructing them like this to fullfill the desired criteria: #define macro(x) do{ \ ... some code line ; \ ... some code line ; \ }while(0) This way you can both... if (a) { macro(a); } and... if (a) macro(a); else { ... } A nice feature of this is that if you use them incorrectly you

Macro evaluation order [duplicate]

半腔热情 提交于 2019-12-05 15:56:34
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: # and ## in macros why the output of second printf is f(1,2) what is the order in which macro is evaluated? #include <stdio.h> #define f(a,b) a##b #define g(a) #a #define h(a) g(a) int main() { printf("%s\n",h(f(1,2))); printf("%s\n",g(f(1,2))); return 0; } output 12 f(1,2) 回答1: From http://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html#Argument-Prescan Macro arguments are completely macro-expanded before they

Can a GHCI config file use CPP macros?

好久不见. 提交于 2019-12-05 15:33:40
I was thinking it would be nice to set up my global GHCI config such that my commonly-used imports occur automatically when the packages that provide them are present. I tried adding this to ~/.ghc/ghci.conf : :set -XCPP #ifdef MIN_VERSION_containers import Data.Set (Set) import qualified Data.Set as Set import Data.Map (Map) import qualified Data.Map as Map #endif But apparently that does not work. > stack repl Configuring GHCi with the following packages: GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help <interactive>:24:1: error: parse error on input ‘#’ <interactive>:29:1: error

Why do people use #ifdef for feature flag tests?

江枫思渺然 提交于 2019-12-05 15:31:35
问题 People recommend #ifdef for conditional compilation by a wide margin. A search for #ifdef substantiates that its use is pervasive. Yet #ifdef NAME (or equivalently #if defined(NAME) and related #ifndef NAME (and #if !defined(NAME) ) have a severe flaw: header.h #ifndef IS_SPECIAL #error You're not special enough #endif source.cpp #include "header.h" gcc -DIS_SPECIAL source.cpp will pass, obviously, as will source1.cpp #define IS_SPECIAL 1 #include "header.h" But, so will source0.cpp #define