c-preprocessor

How to convert #defined string literal to a wide string literal? [duplicate]

五迷三道 提交于 2019-12-19 08:30:21
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to convert concatenated strings to wide-char with the C preprocessor? I have a string literal defined using a #define: #define B "1234\0" How do I use this definition to get this wide string literal at compile time?: L"1234\0" (just the #define d string literal with L prepended to make it into a wide string). I tried this: #define MAKEWIDE(s) L##s but this generates LB . 回答1: Token pasting needs an

How to convert #defined string literal to a wide string literal? [duplicate]

可紊 提交于 2019-12-19 08:30:10
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to convert concatenated strings to wide-char with the C preprocessor? I have a string literal defined using a #define: #define B "1234\0" How do I use this definition to get this wide string literal at compile time?: L"1234\0" (just the #define d string literal with L prepended to make it into a wide string). I tried this: #define MAKEWIDE(s) L##s but this generates LB . 回答1: Token pasting needs an

Implementation of string literal concatenation in C and C++

混江龙づ霸主 提交于 2019-12-19 06:42:17
问题 AFAIK, this question applies equally to C and C++ Step 6 of the "translation phases" specified in the C standard (5.1.1.2 in the draft C99 standard) states that adjacent string literals have to be concatenated into a single literal. I.e. printf("helloworld.c" ": %d: Hello " "world\n", 10); Is equivalent (syntactically) to: printf("helloworld.c: %d: Hello world\n", 10); However, the standard doesn't seem to specify which part of the compiler has to handle this - should it be the preprocessor (

For loop macro which unrolled on the pre-processor phase?

旧街凉风 提交于 2019-12-19 06:30:34
问题 I want to use gcc pre-processor to write almost the same code declaration for 500 times. let's say for demonstration purposes I would like to use a macro FOR_MACRO : #define FOR_MACRO(x) \ #for i in {1 ... x}: \ const int arr_len_##x[i] = {i}; and calling FOR_MACRO(100) will be converted into: const int arr_len_1[1] = {1}; const int arr_len_2[2] = {2}; ... const int arr_len_100[100] = {100}; 回答1: This is not a good idea: While possible in principle, using the preprocessor means you have to

How to print a pound / hash via C preprocessor?

我怕爱的太早我们不能终老 提交于 2019-12-19 06:08:33
问题 I need help doing the following: a preprocessor macro label(x) shall output "#x", e.g., #define label(x) ... if I call label(aname), the output shall be "#aname" (w/o quotes) I know, that the following tries were errors. #define label(x) #x // leads to "x" #define label(x) \#x // is \"x" #define label(x) "#x" // is "#x" (but not the content of x") "#otto" It may exist a kind of escaped # (pound), but I don't know, how to escape... Edit : I run "gcc -E test -o test.html" to get the output. The

what is ## in c?

旧街凉风 提交于 2019-12-19 05:57:42
问题 I have seen this snippet: #define kthread_create(threadfn, data, namefmt, arg...) \ kthread_create_on_node(threadfn, data, -1, namefmt, ##arg) what does ## stand for ? what is the meaning of ## when it appears out of a macro ? 回答1: Contrary to the other answers, this is actually GCC extension. When pasting variable args directly in, a problem occurs if no extra args were passed. Thus, GCC makes ## when used with __VA_ARGS__ or a varargs variable (declared with argname... ). To paste if it

How can I run the MSVC preprocessor and compiler in two separate steps?

牧云@^-^@ 提交于 2019-12-19 05:50:14
问题 I'd like to run the Microsoft Visual Studio Compiler cl.exe without invoking the preprocessor. Is this possible? I thought that simply compiling preprocessed source code (using the /c flag) would make the preprocessor run being a no-op, but apparently that's not the case. I did a bit of benchmarking. Here's a little source file ( main.cpp ) which just includes some code: #include <iostream> #include <string> #include <windows.h> Here are some different compiler invocations and their timings:

What is the usage of #if DEBUG pre-processor directive in C#? When must we use this?

若如初见. 提交于 2019-12-19 05:32:12
问题 What is the usage of #if DEBUG pre-processor directive in C#? When must we use this? 回答1: In Debug mode: #if DEBUG System.Console.WriteLine("Debug version"); #endif System.Console.WriteLine("Output"); Output as Debug version Output In Release mode: #if DEBUG System.Console.WriteLine("Debug version"); #endif System.Console.WriteLine("Output"); Output as Output read this: #if (C# Reference) Usage: If you have a set of values to be tested in the debug mode and not in the release mode you can use

Precedence of -D MACRO and #define MACRO

混江龙づ霸主 提交于 2019-12-19 05:23:37
问题 If I have a C file foo.c and while I have given -DMACRO=1 as command line option for compilation. However, if within the header file also I have #define MACRO 2 Which of these will get precedence? 回答1: The command line options apply ahead of any line read from a file. The file contents apply in the order written. In general, you will get at least a warning if any macro is redefined, regardless of whether the command line is involved. The warning may be silenced if the redefinition doesn't

C pre-processor macro expansion

こ雲淡風輕ζ 提交于 2019-12-18 23:46:09
问题 I'm trying to do (what I would have thought) was a simple macro expansion #define CLEAR_DIGIT(a,b) iconMap[a] &= ~(b) #define R1 4, 16 CLEAR_DIGIT(R1); Now I would expect that to expand to CLEAR_DIGIT(4,16) which expands to iconMap[4] &= ~16 However, it doesn't... If I make CLEAR_DIGIT a function: void ClearDigit(unsigned char a, unsigned char b) { iconMap[a] &= ~b; } #define R1 4, 16 ClearDigit(R1); then it works fine, so R1 being expanded out to the two arguments isn't an issue... Is there