c-preprocessor

How to detect X32 on Windows?

眉间皱痕 提交于 2019-12-06 15:51:14
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 Systems : Microsoft's documentation on Predefined Macros lists the usual suspect, like _M_X64 and _M_AMD64

Expanding a macro to a different default macro if an argument is missing

南笙酒味 提交于 2019-12-06 11:25:18
Is it possible to expand a macro which accepts multiple arguments to a different macro if first argument is not the expected value E.g int main() { PRINT(2, "%d%d\n", i, j); //should expand to syslog(2, "%d%d\n", i, j) PRINT("%d%d\n", i, j); //arg1 which is expected to be an int is not preset. /* This should expand differently may be to a default level say 3. syslog(3, "%d%d\n", i,j); */ } I would have tried this kind of over loading if I knew total number of args. I really recommend to write two separate macros for this, just as you would write two differently named functions for the two

Limiting Scope of #include Directives

一曲冷凌霜 提交于 2019-12-06 10:00:42
Let's say I have a header file with a class that uses std::string . #include <string> class Foo { std::string Bar; public: // ... } The user of this header file might not want std::string to be included in his/her project. So, how do I limit the inclusion to just the header file? The user of your class must include <string> , otherwise their compiler will not know how big a Foo object is (and if Foo 's constructors/destructors are defined inline, then the compiler also won't know what constructor/destructor to call for the string member). This is indeed an irritating side-effect of the C++

Trying to make templates in C

瘦欲@ 提交于 2019-12-06 09:44:57
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 == 0) capacity = 0;\ if (capacity != vector->capacity)\ {\ vector->capacity = capacity;\ if (size == 0) {\

C preprocessor macro expansion

[亡魂溺海] 提交于 2019-12-06 09:26:37
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 However, once the same macro is used more then once, the expansion stops: X(A(A(x))) expands to "A" _A(x),

How to generate a series of random numbers with the C/C++ preprocessor

て烟熏妆下的殇ゞ 提交于 2019-12-06 09:06:16
问题 I would like to generate a series of random numbers with the C preprocessor, and store them in variables for use by my program. OBJECTIVES: I would like to generate a "unique" set of random numbers every time I build my program. A small subset of the variables storing the random numbers will be overwritten with meaningful (i.e. non-random) numbers. I would like it to be impossible for a hacker, by debugging the program or comparing multiple builds, to be able to differentiate the meaningful

How to put a warning disable pragma inside a macro gcc

冷暖自知 提交于 2019-12-06 08:56:43
I need to disable a warning that originates inside the macro '__LOG_W' in following code. To do that, I wrapped this macro inside another macro 'LOG_W' and disabled the warning '-Wold-style-cast' with in that. Then in the code I used the LOG_W instead. However I still get the warning and unable to find out why. Any pointers appreciated. #define LOG_W(expr)\ _Pragma("GCC diagnostic push")\ _Pragma("GCC diagnostic ignored \"-Wold-style-cast\"")\ __LOG_W(DEF, UNKNOWN, expr);\ _Pragma("GCC diagnostic pop") 来源: https://stackoverflow.com/questions/24681881/how-to-put-a-warning-disable-pragma-inside

Is it possible to generate a global list of marked strings at compile time/runtime?

烈酒焚心 提交于 2019-12-06 08:38:23
So, I'm working on translating my C++ app into multiple languages. What I'm currently using is something like: #define TR(x) (lookupTranslatedString( currentLocale(), x )) wcout << TR(L"This phrase is in English") << endl; The translations are from a CSV file which maps the english string to the translated string. "This phrase is in English","Nasa Tagalog itong pagsabi" This is simplified, but that's the basic idea. My question is about generating the list of English phrases that need to be translated. I just need the CSV with all the english phrases, and blank translated phrases. I was hoping

Change Preprocessor value in Objective-C

最后都变了- 提交于 2019-12-06 08:27:38
Is there any way to change a preprocessor value like: #define XValue 50 in Objective-C? 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 #undef XValue #define XValue 100 What about: int global_mutable_value = 50; #define XValue global_mutable_value Or just int XValue = 50; You don't say why you want XValue to be a macro, so we can't tell whether your intentions for it would be satisfied

Equivalent of #define in tcl?

别来无恙 提交于 2019-12-06 07:49:34
问题 Is there a command in tcl that is equivalent to C++ #define? I've seen ways to implement "define" using overloading of the proc function, just wanted to know if anyone knows of a more starightforward way 回答1: Tcl has a mechanism that lets you define aliases to procedures in an interpreter. If you have proc foo {one two three} {do something with $one $two $three} and you find you're always passing $a and $b as the first two arguments, you can write: interp alias {} foo_ab {} foo $a $b And now