c-preprocessor

Undefining functions using preprocessor macros

狂风中的少年 提交于 2019-12-08 07:16:28
问题 I've a log system written in C++ with this type of functions to write on it: void processMessages(); void DEBUG_MSG(const std::string& appender,const char* msg, ...); void INFO_MSG(const std::string& appender,const char* msg, ...); void WARNING_MSG(const std::string& appender, const char* msg, ...); void ERROR_MSG(const std::string& appender, const char* msg, ...); void FATAL_MSG(const std::string& appender, const char* msg, ...); I want to disable via macros in C++. I've read this thread:

Placing a preprocessor directive inside a string literal? [duplicate]

有些话、适合烂在心里 提交于 2019-12-08 04:50:07
问题 This question already has answers here : Stringification of a macro value (3 answers) Closed 3 years ago . I'm trying to use #define to define a string literal (a filepath in this case), but I cannot get the path FROM another #define'd element. In short, I'd like something like this: #define X /var/stuff #define Y "X/stuff.txt" To give me Y as "/var/stuff/stuff.txt" . Is this even possible to do? Thanks beforehand. EDIT: Alternatively, would something like this concat the two literals into

Unqualified-id before string constant

无人久伴 提交于 2019-12-08 04:28:26
问题 On compiling following code I get error "expected unqualified-id before string constant" In file "Notification_Constants.h" namespace NOTIFICATION_CONSTANTS { #define SERVICE_EMAIL "service@company.com" } In file SendEmail.cpp #include "Notification_Constants.h" void UserPreferences::get_senders_email(String &_email) { _email = NOTIFICATION_CONSTANTS::SERVICE_EMAIL; } If i assign like following it works properly, what is the reason for the compilation error. _email = SERVICE_EMAIL; There is a

How to avoid code bloat when using pthreads in C?

ε祈祈猫儿з 提交于 2019-12-08 04:11:32
问题 When writing threaded code in C, I first have to create some struct which includes all the arguments and a wrapper function. This leads to lots of code bloat and is not easy to read. See: struct some_function_args { int arg1; int arg2; int arg3; }; void some_function_wrapper(struct some_function_args* args) { some_function(args->arg1, args->arg2, args->arg3); } int main() { struct my_args; my_args.arg1 = 1; my_args.arg2 = 2; my_args.arg3 = 3; pthread_create(..., some_function_wrapper, &my

How to zip multiple Boost Preprocessor sequences?

我是研究僧i 提交于 2019-12-08 04:07:08
问题 Given multiple Boost Preprocessor sequences: #define S1 (a)(b)(c) #define S2 (1)(2)(3) #define S3 (x1)(x2)(x3) How do I zip them using the preprocessor so the end result would be ((a)(1)(x1))((b)(2)(x2))((c)(3)(x3)) ? Notes I came up with my own answer, but I'm open to accepting better solutions than provided by my answer below in reasonable time. Please refrain from removing the c tag since this Boost.Preprocessor works well with C++ as well as C, and my question targets both languages. 回答1:

How to detect X32 on Windows?

喜欢而已 提交于 2019-12-08 03:51:15
问题 X32 allows one to write programs using 32-bit integers, longs and pointers that run on x86_64 processors. Using X32 has a number of benefits under certain use cases. (X32 is different than X86 or X64; see Difference between x86, x32, and x64 architectures for more details). It appears some Windows Enterprise Server supports X32, but I'm having trouble finding more information on it. That's based on some Intel PDFs, like Intel® Xeon® Processor E5-2400 Series-based Platforms for Intelligent

Is it possible to reliably convert C preprocessor macros to python code?

倖福魔咒の 提交于 2019-12-08 02:32:25
问题 I have a bunch of C macros the operation of which I need to simulate in python. I saw some pointers to pygccxml or ctypeslib etc. Are these the ways to go? Or is there something out there that is better ? The C macros if and when they change, I would like the python implementation to be auto generated rather than having to make manual modifications. Hence the question. my_c_header.h : #ifdef OS #define NUM_FLAGS (uint16_t)(3) #define NUM_BITS (uint16_t)(8) #else #define NUM_FLAGS (uint16_t)(6

C preprocessor macro expansion

本小妞迷上赌 提交于 2019-12-08 01:50:27
问题 I have difficulty understanding how rewriting rules are applied by the C preprocessor in the following context. I have the following macros: #define _A(x) "A" _##x #define _B(x) "B" _##x #define X(x) _##x The idea is that each of these macros uses the concatenation to create a new expression, which can itself be a macro — if its a macro, I'd like it to be expanded: Now, the following expands just like I expect: X(x) expands to _x X(A(x)) expands to "A" _x X(A(B(x))) expands to "A" "B" _x

Trying to make templates in C

元气小坏坏 提交于 2019-12-07 23:23:31
问题 I made a generic vector in C using macros. Is the concept viable or do I get a one-way trip to the bonfire for even thinking about it? #ifndef VECTOR_H #define VECTOR_H #define vector_at(vector, pos) ((vector).data[pos]) #define VECTOR_DEFINITION(type)\ typedef struct {\ size_t size;\ size_t capacity;\ type *data;\ } vector_ ## type ## _t;\ void vector_ ## type ## _reserve(vector_ ## type ## _t *vector, size_t size) {\ size_t capacity = 1;\ while (capacity < size) capacity *= 2;\ if (size ==

Change Preprocessor value in Objective-C

风格不统一 提交于 2019-12-07 21:15:29
问题 Is there any way to change a preprocessor value like: #define XValue 50 in Objective-C? 回答1: If you mean changing it during runtime, then no, as XValue is replaced with 50 before compilation. If you mean changing it in the compilation, then yes, using #undef and #define . Example: XValue = 30; // NOT ALLOWED #undef XValue // ALLOWED #define XValue 30 回答2: #undef XValue #define XValue 100 回答3: What about: int global_mutable_value = 50; #define XValue global_mutable_value Or just int XValue =