c-preprocessor

How can I compile a CUDA program for sm_1X AND sm_2X when I have a surface declaration

↘锁芯ラ 提交于 2019-12-06 07:14:02
问题 I am writing a library that uses a surface (to re-sample and write to a texture) for a performance gain: ... surface<void, 2> my_surf2D; //allows writing to a texture ... The target platform GPU has compute capability 2.0 and I can compile my code with: nvcc -arch=sm_20 ... and it works just fine. The problem is when I am trying to develop and debug the library on my laptop which has an NVIDIA ION GPU with compute capability 1.1 (I would also like my library to be backwards compatible). I

How do I concatenate two macros with a dot between them without inserting spaces?

笑着哭i 提交于 2019-12-06 06:33:15
I'm preprocessing my InfoPlist file to include my revision number. My header looks like this: #import "svn.h" #define APP_VERSION 1.0 #define APP_BUILD APP_VERSION.SVN_REVISION When I check my build version from within the program, it's 1.0 . 123456 . But if I try this: #import "svn.h" #define APP_VERSION 1.0 #define APP_BUILD APP_VERSION ## . ## SVN_REVISION I get error: pasting formed 'APP_VERSION.', an invalid preprocessing token error: pasting formed '.SVN_REVISION', an invalid preprocessing token I've seen this question but it doesn't actually give an answer; the OP didn't actually need

Cancelling std::cout code lines using preprocessor

情到浓时终转凉″ 提交于 2019-12-06 05:34:01
问题 One can remove all calls to printf() using #define printf . What if I have a lot of debug prints like std::cout << x << endl; ? How can I quickly switch off cout << statements in a single file using preprocessor? 回答1: NullStream can be a good solution if you are looking for something quick that removes debug statements. However I would recommend creating your own class for debugging, that can be expanded as needed when more debug functionality is required: class MyDebug { std::ostream &

Template function with macro - accumulate on vector

喜你入骨 提交于 2019-12-06 05:27:15
I want to create a function that get vector<int> run over all his elements and "sum" them according to specific operator I chose . For example , v1 = [3,6,7] so I could calculate by this function - 3+6+7 of 3-6-7 of 3*6*7 etc .. For this I did - #include <iostream> #include <vector> using namespace std; #define OPERATOR(X,Y,OP) X #OP Y template<T> int allVectorWithOperator(vector<int> &myVector, T) { vector<int>::iterator it; vector<int>::iterator oneBeforeFinal; oneBeforeFinal = myVector.end(); oneBeforeFinal -= 2; int sum = 0; for (it = myVector.begin(); it <= oneBeforeFinal; it++) { sum =

Passing a template which requires a comma to a single-argument macro

夙愿已清 提交于 2019-12-06 05:13:40
问题 I have some code that essentially condenses down to #define FOO(a) FOO(std::map<int, int>); But it emits a compile error (too many actual parameters for macro FOO ). Obviously the preprocessor is thinking that I've supplied std::map<int and int> as arguments. Is there a way round this? The preprocessor will not treat a quoted string with a comma in this way. 回答1: This should perhaps ideally be a comment, but SO doesn't support code in comments, so, you can do #include <map> #define T_ARGS( ..

Reusable preprocessor __COUNTER__

谁都会走 提交于 2019-12-06 04:19:19
问题 I am doing some template meta programming, mostly just writing my own compile time list, but I also have some preprocessor magic which I want to use to make things easier if possible. What I am trying to do is create a compile time list of functors. That part is done, but the macros to ease creation (and add to the list) are not. An example in brief: template<typename Functor, typename Tail> struct node { typedef Functor head; typedef Tail tail; }; template <typename Functor, typename Tail>

Using #define one time for multiple source files

為{幸葍}努か 提交于 2019-12-06 04:14:37
问题 Is there a way in Visual C++ to #define something in a cpp file and have it defined in other cpp files as well? 回答1: There are at least two options: Put the definition into a header file and include that header file in all the source files in which you need the definition Use the /D compiler option to define the macro (this can also be set in the project properties under C/C++ -> Preprocessor -> Preprocessor Definitions ) 回答2: definitions.h: #define foo bar class.h: #include "definitions.h"

Compile time check if a function is used/unused c++

旧城冷巷雨未停 提交于 2019-12-06 03:57:09
问题 I'd like to check during compile time if some function of some class is used/not used, and accordingly fail/pass the compilation process. For example if function F1 is called somewhere in the code I want the compilation to succeed, and if function F2 is called I want it to fail. Any ideas on how to do that, with usage of preprocessor, templates or any other c++ metaprogramming technique? 回答1: You can achieve this with a c++11 compiler provided you are willing to modify F2 to include a static

Macro without definition in C

柔情痞子 提交于 2019-12-06 03:53:50
问题 What is the use/applicability of macro function without definition: #ifndef __SYSCALL #define __SYSCALL(a, b) #endif One can find this macro in Linux system in header file /usr/include/asm/msr.h I also notice macro of following kind. #define _M(x) x And only reason to defined this kind of macro that I can think to make code uniform. like in #define SOMETHING (1 << 0). Is there any other hidden(better) use of this kind of macros? An answer with example will be very helpful. Also can someone

Mono for Android preprocessor macros

我只是一个虾纸丫 提交于 2019-12-06 03:31:09
问题 Is there an Android preprocessor macros that Mono for Android defines? I mean very useful things for cross-platform development like: #if WINDOWS...#endif and #if WINDOWS_PHONE...#endif 回答1: __ANDROID__ and additionally for each Android API Level: __ANDROID_4__;__ANDROID_7__;__ANDROID_8__;etc 来源: https://stackoverflow.com/questions/7917859/mono-for-android-preprocessor-macros