preprocessor-directive

What's the meaning of #line in C language?

五迷三道 提交于 2020-11-30 04:24:51
问题 What's the meaning of #line in the C language? Where would it be used? 回答1: It tells the compiler where the following line actually came from. It's usually only the C preprocessor that adds these, for example, when including a file, it tells the compiler (which is basically only seeing one stream of data) that we're looking at a different file. This may sound strange, but the preprocessor simply inserts the header files where you specify your includes, and the compiler works on the whole

Use of # in a macro [duplicate]

让人想犯罪 __ 提交于 2020-06-10 02:57:26
问题 This question already has answers here : C preprocessor: stringize macro and identity macro (2 answers) What does #x inside a C macro mean? (3 answers) How to concatenate twice with the C preprocessor and expand a macro as in “arg ## _ ## MACRO”? (2 answers) Closed 3 years ago . Please explain the code #include <stdio.h> #define A(a,b) a##b #define B(a) #a #define C(a) B(a) main() { printf("%s\n",C(A(1,2))); printf("%s\n",B(A(1,2))); } Output 12 A(1,2) I don't understand, how the first printf

#define used with operators [duplicate]

你说的曾经没有我的故事 提交于 2020-01-30 11:08:07
问题 This question already has answers here : The need for parentheses in macros in C [duplicate] (8 answers) Closed 2 years ago . I know that #define has the following syntax: #define SYMBOL string If I write, for example #define ALPHA 2-1 #define BETA ALPHA*2 then ALPHA = 1 but BETA = 0 .(why ?) But if i write something like this #define ALPHA (2-1) #define BETA ALPHA*2 then ALPHA = 1 and BETA = 2 . Can someone explain me what's the difference between those two ? 回答1: Pre-processor macros

#define used with operators [duplicate]

一个人想着一个人 提交于 2020-01-30 11:06:06
问题 This question already has answers here : The need for parentheses in macros in C [duplicate] (8 answers) Closed 2 years ago . I know that #define has the following syntax: #define SYMBOL string If I write, for example #define ALPHA 2-1 #define BETA ALPHA*2 then ALPHA = 1 but BETA = 0 .(why ?) But if i write something like this #define ALPHA (2-1) #define BETA ALPHA*2 then ALPHA = 1 and BETA = 2 . Can someone explain me what's the difference between those two ? 回答1: Pre-processor macros

#define used with operators [duplicate]

夙愿已清 提交于 2020-01-30 11:04:19
问题 This question already has answers here : The need for parentheses in macros in C [duplicate] (8 answers) Closed 2 years ago . I know that #define has the following syntax: #define SYMBOL string If I write, for example #define ALPHA 2-1 #define BETA ALPHA*2 then ALPHA = 1 but BETA = 0 .(why ?) But if i write something like this #define ALPHA (2-1) #define BETA ALPHA*2 then ALPHA = 1 and BETA = 2 . Can someone explain me what's the difference between those two ? 回答1: Pre-processor macros

Identical template for many functions

烈酒焚心 提交于 2020-01-14 06:13:10
问题 Hello guys (and happy new year!) I'm writing a (not really) simple project in C++ (my first, coming from plain C). I was wondering if there is a way to simplify the definition for multiple functions having the same template pattern. I think an example would be better to explain the problem. The context Let's assume I have a "Set" class which represents a list of numbers, defined as template <class T> class Set { static_assert(std::is_arithmetic<T>(), "Template argument must be an arithmetic

Identical template for many functions

有些话、适合烂在心里 提交于 2020-01-14 06:10:25
问题 Hello guys (and happy new year!) I'm writing a (not really) simple project in C++ (my first, coming from plain C). I was wondering if there is a way to simplify the definition for multiple functions having the same template pattern. I think an example would be better to explain the problem. The context Let's assume I have a "Set" class which represents a list of numbers, defined as template <class T> class Set { static_assert(std::is_arithmetic<T>(), "Template argument must be an arithmetic

Does the program execution always start from main in C?

老子叫甜甜 提交于 2020-01-09 10:33:15
问题 Must program execution start from main, or can the starting address be modified? #include <stdio.h> void fun(); #pragma startup fun int main() { printf("in main"); return 0; } void fun() { printf("in fun"); } This program prints in fun before in main . 回答1: The '#pragma' command is specified in the ANSI standard to have an arbitrary implementation-defined effect. In the GNU C preprocessor, '#pragma' first attempts to run the game 'rogue'; if that fails, it tries to run the game 'hack'; if