preprocessor

Print expression and also echo it

大憨熊 提交于 2020-01-06 06:04:32
问题 I mean to define a function print_echo that replaces print , such that in addition to printing the result of an expression it prints the expression itself. If I simply pass the expression as a string and use eval inside print_echo , it will not know any variable local to the caller function. My current code is def print_echo( expr ) : result = eval( expr ) print( expr + ' => ' + str( result ) + ' ' + str( type( result ) ) ) return But when using def my_func( params ) : a = 2 print_echo( "a" )

Does Delphi's conditional compilation allow the defined symbols to contain values?

做~自己de王妃 提交于 2020-01-03 18:03:14
问题 In Delphi, you can define symbols, just like in C/C++. Delphi: {$DEFINE MY_SYMBOL} C/C++: #define MY_SYMBOL This allows you to check whether the symbol is defined by using {$IFDEF MY_SYMBOL} in Delphi, or #ifdef MY_SYMBOL in C/C++. This is a boolean value - either the symbol is defined during pre-processing or not. However, C/C++ also allows you to assign values to preprocessor symbols. E.g.: #ifdef DEBUG #define DB_HOST "127.0.0.1" #else #define DB_HOST "123.456.789.123" #endif Database

Checking for protocol availability in Swift

▼魔方 西西 提交于 2020-01-03 00:32:12
问题 I am adopting WatchConnectivity, but I am still supporting iOS7 and iOS 8 for which this library is not available. Moreover I am adopting protocol WCSessionDelegate also not supported but this older systems. In ObjectiveC I would have used preprocessing directives to shield this declaration and the protocol adoption from versions not supporting them. How do I handle that in Swift so that the app does not crash on older systems? 回答1: I thank @joern for the suggestion of adopting the protocol

Stringify macro with GNU gfortran

≡放荡痞女 提交于 2020-01-02 06:32:07
问题 How can I stringify a preprocessor macro with GNU gfortran? I would like to pass a macro definition to GNU gfortran which will then be used as a string in the code. Effectively I would like to do this: program test implicit none character (len=:), allocatable :: astring astring = MYMACRO write (*, *) astring end program test and then build with: gfortran -DMYMACRO=hello test.F90 I tried creating various macro, for example: #define STRINGIFY_(x) #x #define STRINGIFY(x) STRINGIFY_(x) ...

how do I add preprocessor #define in devenv command line?

♀尐吖头ヾ 提交于 2020-01-02 01:04:52
问题 Is there a way to add extra preprocessor #define in devenv command line? 回答1: I am not entirely sure what you mean by vcbuild command line but if you mean the Visual C++ command line compiler then you can add defines by add /Dxxxx, e.g. cl.exe /DSHAREWARE .... Additional answer based on comments: You should be able to set the CL environment variable with the extra preprocessor define: SET CL=/DSHAREWARE devenv .... Mere information can be found at MSDN 回答2: The #defines are defined in your

how do I add preprocessor #define in devenv command line?

岁酱吖の 提交于 2020-01-02 01:04:41
问题 Is there a way to add extra preprocessor #define in devenv command line? 回答1: I am not entirely sure what you mean by vcbuild command line but if you mean the Visual C++ command line compiler then you can add defines by add /Dxxxx, e.g. cl.exe /DSHAREWARE .... Additional answer based on comments: You should be able to set the CL environment variable with the extra preprocessor define: SET CL=/DSHAREWARE devenv .... Mere information can be found at MSDN 回答2: The #defines are defined in your

How do I check the TARGET_NAME of my iPhone app on XCode?

不打扰是莪最后的温柔 提交于 2020-01-01 09:04:10
问题 I'm trying to have 2 version of my iPhone application within the same XCode project. The codebase it's almost the same and where I need to have different behaviours I've decided to use preprocessor's conditionals and the ${TARGET_NAME} tag. I've set the OTHER_CFLAGS to contain " -DTARGET_NAME=${TARGET_NAME} ". Then in my code I tried to do #if TARGET_NAME == myApp NSLog(@"pro"); #elif TARGET_NAME == myAppLite NSLog(@"lite"); #endif Unfortunately I always get "lite" printed out since TARGET

Disable or enable code by preprocessor

大憨熊 提交于 2019-12-31 00:03:27
问题 In C++ I'd write bool positive (int a) { #ifdef DEBUG cout << "Checking the number " << a << "\n"; #endif return a > 0; } In OCaml I could write let positive x = begin printf "Checking the number %d\n" x; x > 0 end But how can I disable the printf statement when not in debug mode? 回答1: you can use cppo : https://github.com/mjambon/cppo. This is available via opam, and offers C like preprocessor features. 回答2: Without preprocessing you can simply have a global flag defined as let debug = true

Test for empty macro definition

帅比萌擦擦* 提交于 2019-12-29 05:47:06
问题 I've got a set of debug macros in tracing.hh. Whether it generates code and output is controlled by a macro flag in the real source code: // File: foo.cc #define TRACING 0 #include "tracing.hh" // Away we go . . . TRACEF("debug message"); The flag TRACING should have a value; I usually toggle between 0 and 1. Within tracing.h, #ifdef TRACING will tell me that tracing was defined. #if TRACING controls the definition of functional macros like TRACEF() But what if TRACING has no value? Then #if

Discover the class of a methodinvocation in the Annotation Processor for java

时光毁灭记忆、已成空白 提交于 2019-12-29 04:24:13
问题 I am writing some tools for our build system to enforce some strict calling conventions on methods belonging to classes containing certain annotations. I'm using the Compiler Tree API... What i'm wondering is when traversing the 'tree', how can you tell the type of class/interface for a MethodInvocation. I'm subclassing TreePathScanner with : @Override public Object visitMethodInvocation(MethodInvocationTree node, Trees trees) { } I'm hoping theres a way to tell the type of the class(or