Search Results

Search found 347 results on 14 pages for 'preprocessor'.

Page 1/14 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Remove extra junk from C preprocessor?

    - by Brendan Long
    I'm trying to use the C preprocessor on non-C code, and it works fine except for creating lines like this at the top: # 1 "test.java" # 1 "<built-in>" # 1 "<command-line>" # 1 "test.java" The problem is that these lines aren't valid in Java. Is there any way to get the preprocessor to not write this stuff? I'd prefer not to have to run this through something else to just remove the first 4 lines every time.

    Read the article

  • Can I append to a preprocessor macro?

    - by JCSalomon
    Is there any way in standard C—or with GNU extensions—to append stuff to a macro definition? E.g., given a macro defined as #define quux_list X(foo) X(bar) can I append X(bas) so that it now expands as if I’d defined it #define quux_list X(foo) X(bar) X(bas)? I’m playing with discriminated/tagged unions along these lines: struct quux_foo { int x; }; struct quux_bar { char *s; }; struct quux_bas { void *p; }; enum quux_type {quux_foo, quux_bar, quux_bas}; struct quux { enum quux_type type; union { struct quux_foo foo; struct quux_bar bar; struct quux_bas bas; } t; }; I figure this is a good place for the X-macro. If I define a macro #define quux_table X(foo) X(bar) X(bas) the enumeration & structure can be defined thus, and never get out of sync: #define X(t) quux_ ## t, enum quux_type {quux_table}; #undef X #define X(t) struct quux_ ## t t; struct quux { enum quux_type type; union {quux_table} t; }; #undef X Of course, the quux_* structures can get out of sync, so I’d like to do something like this, only legally: struct quux_foo { int x; }; #define quux_table quux_table X(foo) struct quux_bar { char *s; }; #define quux_table quux_table X(bar) struct quux_bas { void *p; }; #define quux_table quux_table X(bas) (Well, what I really want to be able to do is something like member_struct(quux, foo) { int x; }; but I’m well aware that macros cannot be (re)defined from within macros.) Anyhow, that’s my motivating example. Is there a way to accomplish this? Boost.Preprocessor examples are fine, if you can show me how to make the X-macro technique work with that library.

    Read the article

  • What are the lengths/limits C preprocessor as a language creation tool? Where can I learn more about

    - by Weston C
    In his FAQ @ http://www2.research.att.com/~bs/bs_faq.html#bootstrapping, Bjarne Stroustrup says: To build [Cfront, the first C++ compiler], I first used C to write a "C with Classes"-to-C preprocessor. "C with Classes" was a C dialect that became the immediate ancestor to C++... I then wrote the first version of Cfront in "C with Classes". When I read this, it piqued my interest in the C preprocessor. I'd seen its macro capabilities as suitable for simplifying common expressions but hadn't thought about its ability to significantly add to syntax and semantics on the level that I imagine bringing classes to C took. So now I have a couple of questions on my mind: 1) Are there other examples of this approach to bootstrapping a language off of C? 2) Is the source to Stroustrup's original work available anywhere? 3) Where could I learn more about the specifics of utilizing this technique? 4) What are the lengths/limits of that approach? Could one, say, create a set of preprocessor macros that let someone write in something significantly Lisp/Scheme like?

    Read the article

  • The Bizarre Hidden Powers of the Preprocessor? [closed]

    - by ApprenticeHacker
    The preprocessor in C and C++ deserves an entire essay on its own to explore its rich possibilities for obfuscation. It is true that the C++ (and C) preprocessor can be used for a lot of powerful stuff. #ifdefs and #defines are often used to determine platforms, compilers and backends. Manipulating the code likewise. However, can anyone list some of the most powerful and bizarre things you can do with the preprocessor? The most sinister use of the preprocessor I've found is this: #ifndef DONE #ifdef TWICE // put stuff here to declare 3rd time around void g(char* str); #define DONE #else // TWICE #ifdef ONCE // put stuff here to declare 2nd time around void g(void* str); #define TWICE #else // ONCE // put stuff here to declare 1st time around void g(std::string str); #define ONCE #endif // ONCE #endif // TWICE #endif // DONE This declares different things based on how many times the header is included. Are there any other bizarre unknown powers of the C++ preprocessor?

    Read the article

  • C language preprocessor behavior

    - by khanna_param
    There are different kind of macros in C language, nested macro is one of them. Considering a program with the following macro #define HYPE(x,y) (SQUR(x)+SQUR(y)) #define SQUR(x) (x*x) Using this we can successfully compile to get the result. As we all know the C preprocessor replaces all the occurrence of the identifiers with the replacement-string. Considering the above example I would like to know how many times the C preprocessor traverses the program to replace the macro with the replacement values. I assume it cannot be done in one go.

    Read the article

  • Visual C++ preprocessor definitions

    - by alemjerus
    Is there a way to transfer C++ preprocessor definitions into a custom pre-link step procedure call as a command-line parameter or export them into a file any other way? Example: Let's say, I have a c++ project, and in it's Debug configuration I put a preprocessor definition like MAKUMBA_OBA=0x13 Then I add custom pre-link step which executes some javascript like sarahjessicaparker.js /to tomsrhinoplasty $(MAKUMBA_OBA) It would be great, if it just worked, but I never get a third parameter in my js. So the question is: how to pass a preprocessor definition to s script?

    Read the article

  • Documenting preprocessor defines in Doxygen

    - by Fire Lancer
    Is it possible to document preprocessor defines in Doxygen? I expected to be able to do it just like a variable or function, however the Doxygen output appears to have "lost" the documentation for the define, and does not contain the define its self either. I tried the following /**My Preprocessor Macro.*/ #define TEST_DEFINE(x) (x*x) and /**@def TEST_DEFINE My Preprocessor Macro. */ #define TEST_DEFINE(x) (x*x) I also tried putting them within a group (tried defgroup, addtogroup and ingroup) rather than just at the "file scope" however that had no effect either (although other items in the group were documented as intended). I looked through the various Doxygen options, but couldn't see anything that would enable (or prevent) the documentation of defines.

    Read the article

  • C++ Preprocessor string literal concatenation

    - by ezpz
    I found this regarding how the C preprocessor should handle string literal concatenation (phase 6). However, I can not find anything regarding how this is handled in C++ (does C++ use the C preprocessor?). The reason I ask is that I have the following: const char * Foo::encoding = "\0" "1234567890\0abcdefg"; where encoding is a static member of class Foo. Without the availability of concatenation I wouldnt be able to write that sequence of characters like that. const char * Foo::encoding = "\01234567890\0abcdefg"; Is something entirely different due to the way \012 is interpreted. I dont have access to multiple platforms and I'm curious how confident I should be that the above is always handled correctly - i.e. I will always get { 0, '1', '2', '3', ... }

    Read the article

  • C language preprocessor behavior

    - by khanna_param
    There are different kind of macros in C language, nested macro is one of them. Considering a program with the following macro #define HYPE(x,y) (SQUR(x)+SQUR(y)) #define SQUR(x) (x*x) Using this we can successfully compile to get the result. As we all know the C preprocessor replaces all the occurrence of the identifiers with the replacement-string. Considering the above example I would like to know how many times the C preprocessor traverses the program to replace the macro with the replacement values. I assume it cannot be done in one go.

    Read the article

  • Use a template parameter in a preprocessor directive?

    - by Ranju V
    Is it possible to use a non-type constant template parameter in a preprocessor directive? Here's what I have in mind: template <int DING> struct Foo { enum { DOO = DING }; }; template <typename T> struct Blah { void DoIt() { #if (T::Doo & 0x010) // somecode here #endif } }; When I try this with something like Blah<Foo<0xFFFF>>, VC++ 2010 complains something about unmatched parentheses in the line where we are trying to use "#if". I am guessing the preprocessor doesn't really know anything about templates and this sort of thing just isn't in its domain. What say? Thanks!

    Read the article

  • Writing preprocessor directives to get string

    - by Dave18
    Can you write preprocessor directives to return you a std::string or char*? For example: In case of integers: #define square(x) (x*x) int main() { int x = square(5); } I'm looking to do the same but with strings like a switch-case pattern. if pass 1 it should return "One" and 2 for "Two" so on..

    Read the article

  • Mimic C preprocessor with Python/Ruby?

    - by prosseek
    I need to mimic the preprocessor feature of C with Python. If I want to run the debug release, I use as follows with C #ifdef DEBUG printf(...) #endif I just use -DDEBUG or similar to trigger it on or off. What method can I use for Python/Ruby? I mean, what should I do to control the behavior of python/ruby scripts in such a way that I can change a variable that affects all the script files in a project?

    Read the article

  • gcc run "light" preprocessor

    - by Claudiu
    Is there any way to run the gcc preprocessor, but only for user-defined macros? I have a few one-liners and some #ifdef etc... conditionals, and I want to see what my code looks like when just those are expanded. As it is, the includes get expanded, my fprintf(stderr)s turn into fprintf(((__getreeent())-_stderr), etc...

    Read the article

  • C preprocessor: using #if inside #define?

    - by Wxy
    I want to write a macro that spits out code based on the boolean value of its parameter. So say DEF_CONST(true) should be expanded into "const", and DEF_CONST(false) should be expanded into nothing. Clearly the following doesn't work because we can't use another preprocessor inside #defines: #define DEF_CONST(b_const) \ #if (b_const) \ const \ #endif Any idea about how to do it?

    Read the article

  • How to use Preprocessor directives in MVC aspx pages

    - by Zuber
    I am using MinifyJS.tt which is a T4 template to minify all my JS files automatically. In my aspx files, I am referencing all the javascript files. Now, I want to add a condition (maybe compiler directive) to use the original JS file when I am debugging the application, and to use the minified JS files when I simply run the application without debug. I tried using #if in the aspx page, but that did not seem to work. Can we make use of preprocessor directives in aspx pages? Is there an alternative way to achieve my goal?

    Read the article

  • Can I see shader preprocessor output?

    - by GLaddict
    I am using #defines, which I pass runtime to my shader sources based on program state, to optimize my huge shaders to be less complex. I would like to write the optimized shader to a file so that next time I run my program, I do not have to pass the #defines again, but I can straight compile the optimized shaders during program startup because now I know what kind of shaders by program needs. Is there a way to get the result from shader preprocessor? I can of course store the #define values to a file and based on that compile the shaders during program startup but that would not be as elegant.

    Read the article

  • Preprocessor Conditionals

    - by Mike
    I was wondering if it would be possible to have a define which changes values at some point in the code be used in a conditional. Basically something like this: //////////////////////////////////////////// SomeFile.cpp #define SHUTDOWN false while(window->isOpen()) { if(SHUTDOWN) window->close(); // Rest of the main loop } //////////////////////////////////////////// SomeOtherFile.cpp if(Escape.isPressed()) { #undef SHUTDOWN #define SHUTDOWN true } Thus causing the app to close. If it's not, would having a function like RenderWindow* getWindow() { return window; } and then calling if(Escape.isPressed()) getWindow()->close(); The best way to do it? I'd rather not go that route because the classes that are calling the key event are members of the class controlling the main loop and the window, so I'd have to set pointers to the containing class in the smaller classes to call getWindow() and it just seems like a more complicated method. But if I can't do it with preprocessor directives I'll just have to use pointers to the parent class.

    Read the article

  • How do you perform macro expansion within #ifdef?

    - by Malvineous
    Hi all, I have some fairly generic code which uses preprocessor macros to add a certain prefix onto other macros. This is a much simplified example of what happens: #define MY_VAR(x) prefix_##x "prefix_" is actually defined elsewhere, so it will be different each time the file is included. It works well, but now I have some code I would like to skip if one of the tokens doesn't exist, but this doesn't work: #if defined MY_VAR(hello) What I want it to expand to is this: #ifdef prefix_hello But I can't figure out how. I need to use the MY_VAR() macro to do the expansion, so I can't just hardcode the name. (It's actually for some testing code, the same code gets included with a different prefix each time to test a bunch of classes, and I want to skip a couple of tests for a handful of the classes.) Is this possible with the C++ preprocessor?

    Read the article

  • Any other preprocessor directives in VBScript/Classic ASP?

    - by Frank
    The only pre-process directive that I know about in VBScript / Classic ASP is the #include. I don't know if that is the official name but I'm basically looking for code that can execute code or other instructions before the general VBScript. Are there any other such directives in VBScript? Such as #If or something? I'd like to be able to conditionally include or exclude a certain include file.

    Read the article

  • Visual Studio 2008 Preprocessor wierdness

    - by Canacourse
    We have set-up a simple versioning system for our builds to ensure the built files always indicate whether they are Beta Debug or Beta Release builds I moved the file version info to to myapp.rc2 and created version.h // version.h // _DEBUG is defined by VS #define _BETA #ifdef _BETA #define FILE_DESC1 _T("BETA ") #else #define FILE_DESC1 // blank on purpose #endif #ifdef _DEBUG #define FILE_DESC2 _T("Debug Version ") #else #define FILE_DESC2 _T("Release Version ") // this is greyed out in the ide when building #endif #define FILE_DESC FILE_DESC1 FILE_DESC2 // myapp.rc2 include "version.h" #ifndef _T #define _T(x) x #endif VS_VERSION_INFO VERSIONINFO FILEVERSION PROD_VER_MJR,PROD_VER_MIN,PROD_VER_UPD,JOBUILDER_BUILD PRODUCTVERSION PROD_VER_MJR,PROD_VER_MIN FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L #else FILEFLAGS 0x0L #endif FILEOS 0x4L FILETYPE 0x1L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904e4" BEGIN VALUE "CompanyName", COMPANY_NAME VALUE "FileDescription", FILE_DESC VALUE "FileVersion", JOBBUI_VERSION VALUE "InternalName", "MyApp.exe" VALUE "LegalCopyright", COPYRIGHT VALUE "OriginalFilename", "MyApp.exe" VALUE "ProductName", PRODUCT_NAME VALUE "ProductVersion", PRODUCT_VERSION VALUE "Comments", COMMENTS END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1252 END END However when the exe is built in the debug output directory the file description always incorrectly says "BETA Release Version" instead of "BETA Debug Version" Yet the IDE indicates that "#define FILE_DESC2 _T("Debug Version ")" would be used. Why might this be? I have used these files on another project and they work correctly. Thank You...

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >