c-preprocessor

C++ Set value for a char**

耗尽温柔 提交于 2020-01-06 18:32:50
问题 I'm trying to assign a value to a char** variable. In my foo.h I've defined a couple of variables such as #define APIOCTET int #define APILONG long #define APICHAR char #define APISTRING char* Now in my foo.cpp I'm tryng to use a method where APILONG apiInitialize(APISTRING filePath, APISTRING* outputString) { //open text file to where output will be printed //do other stuff, etc.. //return result; } I'd like to assign a value to my APISTRING* outputString but I just can't figure out how to

Stringify Endpoint for Xcode LLVM Processor Macros

蹲街弑〆低调 提交于 2020-01-06 14:35:51
问题 In the "Apple LLVM 7.0 - Preprocessing" section under the "Build Settings" tab, I've defined a Preprocessor Macros as: STR(arg)=#arg HUBNAME=STR("myhub") HUBLISTENACCESS=STR("Endpoint=sb://abc-xyz.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=JKLMNOP=") In my code, I'm trying to refer to the value of HUBLISTENACCESS as a string: SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:@HUBLISTENACCESS notificationHubPath:

How to use C macro's (#define) to alter calls but not prototypes

ε祈祈猫儿з 提交于 2020-01-06 08:56:13
问题 Older code in our application contains calls to malloc , realloc and free . With our updated code, our own implementations are called instead of the standard runtime ones. Examples are shown below, #define malloc(s) OurMalloc(s) #define free(p) OurFree(p) This works fine for the updated code and for the newer C++ code we simply implement global new and delete operators, so the C++ solution is 'cleaner'. The problem is that we now have to include a 3rd party library, which has classes that

Can I force cmake to include my header file in specific targets?

a 夏天 提交于 2020-01-06 05:08:24
问题 I have a header file which overrides malloc with a macro. Using add_definitions(-include ../include/failing-malloc-test.h) I'm able to force cmake to include this header file in all targets. The problem is that I only want to have my header file included in some targets(test targets and so on). I tried achieving this using target_compile_definition , but I couldn't achieve the same effect, because target_compile_definition seems to work different than add_definitions . Currently the only

How to get preprocessed code from Dev-c++ under Windows XP?

时光毁灭记忆、已成空白 提交于 2020-01-05 04:24:16
问题 How to get preprocessed C++ code from DevC++ under Windows XP? I've read about creating gcc -E file.cpp file, but I still can't connect the dots, how to run this file? After I've compiled it everything went as usual. 回答1: You simply can't 'run' a preprocessed file. You can just compile and run it, or inspect it for what the preprocessor produced. E.g. when using GCC you can run gcc file.cpp -E <all preprocessor options as set from the IDE> -o file_preprocessed.cpp to get the file_preprocessed

Override C code to throw a C++ exception?

拈花ヽ惹草 提交于 2020-01-05 03:43:09
问题 I have a C library (callable from C and C++ code) which handles invalid input by simply exiting. It looks like this #ifdef __cplusplus extern "C" { #endif void exitWithError(const char* func) { printf("woopsie in %s", func); exit(1); } void myfunc(int i) { if (i < 0) exitWithError(__func__); } #ifdef __cplusplus } #endif This library is compiled in "C mode", even when linked with C++ code. I.e. using g++ -x c <abovelibrary.c> I'm using this library in C++ code, and desire it to throw an

How to enforce project-wide unique ids/error codes for easily finding the origin of the error in source code?

对着背影说爱祢 提交于 2020-01-04 17:00:26
问题 It is convenient to use unique error codes that the user will see on an error. This will make it easier to locate the origin of the error for the developer (just do a search in the source code for the error code), thus saving time. Example: void f() { std::cout << "UNIQUE001 " << "Error : The query failed" << std::endl; } void g() { f(); } int main() { g(); return 0; } In the example, the user reports the error ("UNIQUE001 Error : The query failed"). The developer just does a project-wide

How to “interleave” C/C++ souce with my string (only inside functions at appropriate places)?

こ雲淡風輕ζ 提交于 2020-01-04 06:59:42
问题 For example, there is the source: void func1() { func3(); if(qqq) { func2(); } func4( ); } It should be transformed to: void func1() { MYMACRO func3(); MYMACRO if(qqq) { MYMACRO func2(); MYMACRO } MYMACRO func4( ); MYMACRO } I.e. to insert "MYMACRO\n" at the end of each line where statement can be, only inside functions. How to do it easily? Should I use regular expressions? What tools should I use? For example, can gcc output all line numbers of all statement begins (or ends) inside

How to “interleave” C/C++ souce with my string (only inside functions at appropriate places)?

落花浮王杯 提交于 2020-01-04 06:59:06
问题 For example, there is the source: void func1() { func3(); if(qqq) { func2(); } func4( ); } It should be transformed to: void func1() { MYMACRO func3(); MYMACRO if(qqq) { MYMACRO func2(); MYMACRO } MYMACRO func4( ); MYMACRO } I.e. to insert "MYMACRO\n" at the end of each line where statement can be, only inside functions. How to do it easily? Should I use regular expressions? What tools should I use? For example, can gcc output all line numbers of all statement begins (or ends) inside

#define, #ifdef #undef #endif

青春壹個敷衍的年華 提交于 2020-01-04 06:34:26
问题 I have the following code #define PROC_ADD void main(void) { while(1) { #ifdef PROC_ADD // Do this code here then undefined it to run the code in the else // processing work #undef PROC_ADD #else // now that PROC_ADD has been undefined run this code // processing work #endif } } However, it will run the code. But it won't run the code in the else after the PROC_ADD has been undefined. I think the reason could be that you can only define and undefine at compile time, and not at run-time.