c-preprocessor

Preprocessor directives in C#

邮差的信 提交于 2021-02-19 07:47:10
问题 In C#, if preprocessor directives are instructions pre-processed before actual compilation then why is it not executed first in this program? static void Main(string[] args) { Program1.display(); Program2 p2 = new Program2(); p2.show(); #if DEBUG Console.WriteLine("DEBUG from preprocessor directive is working!"); #endif } Expected Output: DEBUG from preprocessor directive is working! .......(from display()) .......(from show()) But Actual Output: .......(from display()) .......(from show())

Expand #includes to a text file for C++

泄露秘密 提交于 2021-02-19 05:23:35
问题 Is it possible to expand out #include lines of a c++ file, probably using the C preprocessor, such that I can read an extended file without #includes , but instead with the files that are #include d? To be concrete, if I have fileA.cpp: #include "fileB.H" int main() { //do whatever return(0); } fileB.H: #include "fileC.H" //Some lines of code fileC.H //Some other lines of code And output: //Some other lines of code //Some lines of code int main() { //do whatever return(0); } Essentially, copy

Expand #includes to a text file for C++

ぐ巨炮叔叔 提交于 2021-02-19 05:19:06
问题 Is it possible to expand out #include lines of a c++ file, probably using the C preprocessor, such that I can read an extended file without #includes , but instead with the files that are #include d? To be concrete, if I have fileA.cpp: #include "fileB.H" int main() { //do whatever return(0); } fileB.H: #include "fileC.H" //Some lines of code fileC.H //Some other lines of code And output: //Some other lines of code //Some lines of code int main() { //do whatever return(0); } Essentially, copy

Recursive C macro not expanded

和自甴很熟 提交于 2021-02-16 21:25:13
问题 I am working on a recursive macro. However, it seems that it is not expanded recursively. Here is a minimal working example to show what I mean: // ignore input, do nothing #define ignore(...) // choose between 6 names, depending on arity #define choose(_1,_2,_3,_4,_5,_6,NAME,...) NAME // if more than one parameter is given to this macro, then execute f, otherwise ignore #define ifMore(f,...) choose(__VA_ARGS__,f,f,f,f,f,ignore)(__VA_ARGS__) // call recursively if there are more parameters

Interpreting C pre pre processor code

自古美人都是妖i 提交于 2021-02-16 14:54:26
问题 Given #define LOG_OBJECT(object) (NSLog(@"" #object @" %@ %@:%d”, [object description], [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__)); The statement LOG_OBJECT(self); will produce: 2014-07-18 17:43:30.041 FrogCamera[12484:2144843] self ViewController.m:20 I wish to understand how the preprocessor code works. How can I see the statement that the pre processor produced? Specifically: Why the whole #define statement is wrapped in ( ) ? Is #object a text replacement for

Error 1 error LNK1104 after change Preprocess to a File

佐手、 提交于 2021-02-10 07:45:37
问题 I had to use a preprocessor, so I changed: Configuration Properties -> C++ -> Preprocessor -> Preprocess to a File -> Yes And got the error: Error 1 error LNK1104: cannot open file 'Debug\asnreal.obj' The solution to this problem: I had to add quotes around the path to my .lib file in Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies . I do not understand what kind of file .lib? Where is it? In my project, it is not. What do I need to specify in Additional

How to catch undefined macro in preprocessor #if condition?

我怕爱的太早我们不能终老 提交于 2021-02-08 21:20:57
问题 Based on this question How to catch empty defined macro with gcc? I have another problem. How to catch undefined macro in preprocessor #if condition? Example code: #include <stdio.h> int main() { #if ENABLE_SOMETHING == 1 ... do something .. #endif return 0; } Is there a way to catch error/warning when ENABLE_SOMETHING is not set using gcc compiler(maybe some flag)? Or maybe there are external tools which I can use? I know than i can write something like this : #ifndef ENABLE_SOMETHING #error

C macro get typeof argument

▼魔方 西西 提交于 2021-02-08 17:01:01
问题 I am trying to write a macro to assist with object oriented programming in C. As I store the class information in a constant struct, I need to create a macro that does the following: Take the type of the object (typeof the derefenced pointer) Append _info to get the name of the desired classInfo struct Take the address of that symbol so it can be passed to the function Call the destroyObject function with a pointer to the class struct and the object itself An example: queue_t* p = NULL;

C Preprocessor stringification (again) [duplicate]

核能气质少年 提交于 2021-02-08 06:34:49
问题 This question already has answers here : Can the C preprocessor perform integer arithmetic? (6 answers) Closed 1 year ago . Is it possible to have stringification after numeric evaluation? This is better explained with a simple example: #define A 1 #define B 2 #define SUM (A + B) #define STR_IMPL_(x) #x #define STR(x) STR_IMPL_(x) char *sum = STR(SUM); As written this generates the single line: char *sum = "(1 + 2)"; Is it possible, somehow, to generate char *sum = "3"; instead? I suspect

BOOST_PP expand sequence in the empty sequence case

我怕爱的太早我们不能终老 提交于 2021-02-08 02:58:30
问题 Using BOOST_PP I can expand a macro into multiple comma separated values with an additional token, as can be seen in the below code. However, it doesn't work in the no-argument case. #define BOOST_PP_VARIADICS #include <boost/preprocessor/punctuation/comma_if.hpp> #include <boost/preprocessor/seq/for_each_i.hpp> #include <boost/preprocessor/variadic/to_seq.hpp> #define ADD_TOKEN(r, token, i, e) \ BOOST_PP_COMMA_IF(i) token(e) #define WRAP(...) \ BOOST_PP_SEQ_FOR_EACH_I(ADD_TOKEN, decltype,