Search Results

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

Page 7/14 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Can I execute a "variable statements" within a function and without defines.

    - by René Nyffenegger
    I am facing a problem that I cannot see how it is solvable without #defines or incuring a performance impact although I am sure that someone can point me to a solution. I have an algorithm that sort of produces a (large) series of values. For simplicity's sake, in the following I pretend it's a for loop in a for loop, although in my code it's more complex than that. In the core of the loop I need to do calculations with the values being produced. Although the algorithm for the values stays the same, the calculations vary. So basically, what I have is: void normal() { // "Algorithm" producing numbers (x and y): for (int x=0 ; x<1000 ; x++) { for (int y=0 ; y<1000 ; y++) { // Calculation with numbers being produced: if ( x+y == 800 && y > 790) { std::cout << x << ", " << y << std::endl; } // end of calculation }} } So, the only part I need to change is if ( x+y == 800 && y > 790) { std::cout << x << ", " << y << std::endl; } So, in order to solve that, I could construct an abstract base class: class inner_0 { public: virtual void call(int x, int y) = 0; }; and derive a "callable" class from it: class inner : public inner_0 { public: virtual void call(int x, int y) { if ( x+y == 800 && y > 790) { std::cout << x << ", " << y << std::endl; } } }; I can then pass an instance of the class to the "algorithm" like so: void O(inner i) { for (int x=0 ; x<1000 ; x++) { for (int y=0 ; y<1000 ; y++) { i.call(x,y); }} } // somewhere else.... inner I; O(I); In my case, I incur a performance hit because there is an indirect call via virtual function table. So I was thinking about a way around it. It's possible with two #defines: #define OUTER \ for (int x=0 ; x<1000 ; x++) { \ for (int y=0 ; y<1000 ; y++) { \ INNER \ }} // later... #define INNER \ if (x + y == 800 && y > 790) \ std::cout << x << ", " << y << std::endl; OUTER While this certainly works, I am not 100% happy with it because I don't necessarly like #defines. So, my question: is there a better way for what I want to achieve?

    Read the article

  • MACRO Question: Returning pointer to a certain value

    - by Andrei Ciobanu
    Is it possible to write a MACRO that has a type and a value as its input parameters (MACRO(type,value)), and returns a valid pointer to a location that holds the submitted value. This macro should perform like the following function, but in a more generic manner: int *val_to_ptr(int val){ int *r = NULL; r = nm_malloc(sizeof(*r)); *r = val; return r; } Where nm_malloc() is a failsafe malloc. The Macro usage should be compatible with this usage: printf("%d",*MACRO(int,5)); Is it possible to achieve that ?

    Read the article

  • How can I generate a list of #define values from C code?

    - by djs
    I have code that has a lot of complicated #define error codes that are not easy to decode since they are nested through several levels. Is there any elegant way I can get a list of #defines with their final numerical values (or whatever else they may be)? As an example: <header1.h> #define CREATE_ERROR_CODE(class, sc, code) ((class << 16) & (sc << 8) & code)) #define EMI_MAX 16 <header2.h> #define MI_1 EMI_MAX <header3.h> #define MODULE_ERROR_CLASS MI_1 #define MODULE_ERROR_SUBCLASS 1 #define ERROR_FOO CREATE_ERROR_CODE(MODULE_ERROR_CLASS, MODULE_ERROR_SUBCLASS, 1) I would have a large number of similar #defines matching ERROR_[\w_]+ that I'd like to enumerate so that I always have a current list of error codes that the program can output. I need the numerical value because that's all the program will print out (and no, it's not an option to print out a string instead). Suggestions for gcc or any other compiler would be helpful.

    Read the article

  • What is DEFAULT_CC in function declaration?

    - by humoeba
    I'm relatively new to C, and am curious what this syntax means in a function declaration: int DEFAULT_CC foo(void) where DEFAULT_CC is probably defined somewhere else as: #define DEFAULT_CC "cc" Is this a direction to use a certain compiler or something?

    Read the article

  • C++ Macro problem, not replacing all values

    - by JP
    I have the following 2 macros: #define SCOPED_ENUM_HEADER(NAME) struct NAME{ enum _NAME{ #define SCOPED_ENUM_FOOTER(NAME) };}; typedef NAME::_NAME NAMEtype; Only the first instance of NAME get replaced by the passed NAME. What's wrong with it? Is is to be used in such a way: SCOPED_ENUM_HEADER(LOGLEVEL) UNSET, FILE, SCREEN SCOPED_ENUM_FOOTER(LOGLEVEL) Thanks you

    Read the article

  • How to make the first invocation of a macro different from all the next ones ?

    - by LB
    Hi, that may be really simple but i'm unable to find a good answer. How can I make a macro representing first a certain value and then a different one ? I know that's nasty but i need it to implicitly declare a variable the first time and then do nothing. This variable is required by other macros that i'm implementing. Should i leverage "argument prescan" ? thanks for the answers. EDIT To make things clearer. Suppose i have a macro FOO, and I do something like FOO FOO FOO I would like the result to be foo bar bar I don't want the actual code to be cluttered by ifndef. The programmer should only have to write macro invocations.

    Read the article

  • Difference between macros and functions in C in relation to instruction memory and speed

    - by DAHANS
    To my understanding the difference between a macro and a function is, that a macro-call will be replaced by the instruction in the definition, and a function does the whole push, branch and pop -thing. Is this right, or have I understand something wrong? Additionally, if this is right, it would mean, that macros would take more space, but would be faster (because of the lack of the push,branch and pop instructions.), wouldn't it?

    Read the article

  • What types of conditions can be used for conditional compilation in C++?

    - by user1002288
    This is an exam question for C++: Which of the following statements accurately describe the condition that can be used for conditional compilation in C++? A. The condition can depend on the value of environment variables. B. The condition can depend on the value of any const variables. C. The condition can depend on the value of program variables. D. The condition can use the sizeof() operator to make decision about compiler-dependent operations based on the size of standard data type. E. The condition must evaluate to either a 0 or 1 during preprocessing. I think the answer is E. Is this correct?

    Read the article

  • difference between #define and enum{} in C

    - by guest
    when should one use enum {BUFFER = 1234}; over #define BUFFER 1234 ? what are the advantages enum brings compared to #define? i know, that #define is just simple text substitution and enum names the constant somehow. but why would one need that at all?

    Read the article

  • Translate sequence in macro parameters to separate macros

    - by Alex Tiger
    How to acces each element in macro if the definition is like MACRO(name, seq) and the code is like: MACRO("TheName", (Elem1) (Elem2) (Elem3) ) I want to generate the next code: MACRO("TheName", ELEMMACRO(Elem1) ELEMMACRO(Elem2) ELEMMACRO(Elem3) ) Or something like that. In other words, I want to process every parameter separately (I don't care of definition, even if it will be something like MACRO("TheName", Elem1, Elem2, Elem3 ) There could be more elements, there could be less. I have tried V_ARGS (I need it only for gcc), but I can only copy all the elements by that, not to process them separately. What can I do? P.S. Because of some reasons, I can't use Boost.

    Read the article

  • How to use __LINE__ in a string

    - by John
    Just using it as a method parameter is fine but what about an easy way to use it in strings? For instance say I have this: 11 void myTest() 12 { 13 if(!testCondition) 14 logError("testcondition failed"); 15 } And I want the output to be: "myTest line 14: testcondition failed" How can I write logError? Does it have to be some monstrosity of a macro?

    Read the article

  • Why does defined(X) not work in a preprocessor definition without a space?

    - by Devin
    A preprocessor definition that includes defined(X) will never evaluate to true, but (defined X) will. This occurs in MSVC9; I have not tested other preprocessors. A simple example: #define FEATURE0 1 #define FEATURE1 0 #define FEATURE2 1 #define FEATURE3 (FEATURE0 && !FEATURE1 && (defined(FEATURE2))) #define FEATURE4 (FEATURE0 && !FEATURE1 && (defined FEATURE2)) #define FEATURE5 (FEATURE0 && !FEATURE1 && (defined (FEATURE2))) #if FEATURE3 #pragma message("FEATURE3 Enabled") #elif (FEATURE0 && !FEATURE1 && (defined(FEATURE2))) #pragma message("FEATURE3 Enabled (Fallback)") #endif #if FEATURE4 #pragma message("FEATURE4 Enabled") #elif (FEATURE0 && !FEATURE1 && (defined FEATURE2)) #pragma message("FEATURE4 Enabled (Fallback)") #endif #if FEATURE5 #pragma message("FEATURE5 Enabled") #elif (FEATURE0 && !FEATURE1 && (defined (FEATURE2))) #pragma message("FEATURE5 Enabled (Fallback)") #endif The output from the compiler is: 1FEATURE3 Enabled (Fallback) 1FEATURE4 Enabled 1FEATURE5 Enabled Working cases: defined (X), defined( X ), and defined X. Broken case: defined(X) Why is defined evaluated differently when part of a definition, as in the #if cases in the example, compared to direct evaluation, as in the #elif cases in the example?

    Read the article

  • How to increment a value using a C-Preprocessor in Objective-C?

    - by mystify
    Example: I try to do this: static NSInteger stepNum = 1; #define METHODNAME(i) -(void)step##i #define STEP METHODNAME(stepNum++) @implementation Test STEP { // do stuff... [self nextFrame:@selector(step2) afterDelay:1]; } STEP { // do stuff... [self nextFrame:@selector(step3) afterDelay:1]; } STEP { // do stuff... [self nextFrame:@selector(step4) afterDelay:1]; } // ... When building, Xcode complains that it can't increment stepNum. This seems logical to me, because at this time the code is not "alive" and this pre-processing substitution stuff happens before actually compiling the source code. Is there another way I could have an variable be incremented on every usage of STEP macro, the easy way?

    Read the article

  • Preprocessor "macro function" vs. function pointer - best practice?

    - by Dustin
    I recently started a small personal project (RGB value to BGR value conversion program) in C, and I realised that a function that converts from RGB to BGR can not only perform the conversion but also the inversion. Obviously that means I don't really need two functions rgb2bgr and bgr2rgb. However, does it matter whether I use a function pointer instead of a macro? For example: int rgb2bgr (const int rgb); /* * Should I do this because it allows the compiler to issue * appropriate error messages using the proper function name, * not to mention possible debugging benefits? */ int (*bgr2rgb) (const int bgr) = rgb2bgr; /* * Or should I do this since it is merely a convenience * and they're really the same function anyway? */ #define bgr2rgb(bgr) (rgb2bgr (bgr)) I'm not necessarily looking for a change in execution efficiency as it's more of a subjective question out of curiosity. I am well aware of the fact that type safety is neither lost nor gained using either method. Would the function pointer merely be a convenience or are there more practical benefits to be gained of which I am unaware?

    Read the article

  • Preprocessor #define vs. function pointer - best practice?

    - by Dustin
    I recently started a small personal project (RGB value to BGR value conversion program) in C, and I realised that a function that converts from RGB to BGR can not only perform the conversion but also the inversion. Obviously that means I don't really need two functions rgb2bgr and bgr2rgb. However, does it matter whether I use a function pointer instead of a macro? For example: int rgb2bgr (const int rgb); /* * Should I do this because it allows the compiler to issue * appropriate error messages using the proper function name, * not to mention possible debugging benefits? */ int (*bgr2rgb) (const int bgr) = rgb2bgr; /* * Or should I do this since it is merely a convenience * and they're really the same function anyway? */ #define bgr2rgb(bgr) (rgb2bgr (bgr)) I'm not necessarily looking for a change in execution efficiency as it's more of a subjective question out of curiosity. I am well aware of the fact that type safety is neither lost nor gained using either method. Would the function pointer merely be a convenience or are there more practical benefits to be gained of which I am unaware?

    Read the article

  • How to increment a value using a C-Preprocessor?

    - by mystify
    Example: I try to do this: static NSInteger stepNum = 1; #define METHODNAME(i) -(void)step##i #define STEP METHODNAME(stepNum++) @implementation Test STEP { // do stuff... [self nextFrame:@selector(step2) afterDelay:1]; } STEP { // do stuff... [self nextFrame:@selector(step3) afterDelay:1]; } STEP { // do stuff... [self nextFrame:@selector(step4) afterDelay:1]; } // ... When building, Xcode complains that it can't increment stepNum. This seems logical to me, because at this time the code is not "alive" and this pre-processing substitution stuff happens before actually compiling the source code. Is there another way I could have an variable be incremented on every usage of STEP macro, the easy way?

    Read the article

  • Django-imagekit: how to reduce image quality with a preprocessor_spec ?

    - by pierre-guillaume-degans
    Hi, please excuse me for my ugly english :p I've created this simple model class, with a Preprocessor to reduce my photos'quality (the photos'extension is .JPG): from django.db import models from imagekit.models import ImageModel from imagekit.specs import ImageSpec from imagekit import processors class Preprocessor(ImageSpec): quality = 50 processors = [processors.Format] class Picture(ImageModel): image = models.ImageField(upload_to='pictures') class IKOptions: preprocessor_spec = Preprocessor The problem : pictures'quality are not reduced. :( Any idea to fix it ? Thank you very much ;)

    Read the article

  • CFLAGS vs CPPFLAGS

    - by EB
    I understand that CFLAGS (or CXXFLAGS for C++) are for the compiler, whereas CPPFLAGS is used by the preprocessor. But I still don't understand the difference. I need to specify an include path for a header file that is included with #include -- because #include is a preprocessor directive, is the preprocessor (CPPFLAGS) the only thing I care about? Under what circumstances do I need to give the compiler an extra include path? In general, if the preprocessor finds and includes needed header files, why does it ever need to be told about extra include directories? What use is CFLAGS at all? (In my case, I actually found that BOTH of these allow me to compile my program, which adds to the confusion... I can use CFLAGS OR CPPFLAGS to accomplish my goal (in autoconf context at least). What gives?)

    Read the article

  • PHP - A Widely-Used Scripting Language

    Typified as interpreted script language, PHP - a recursive acronym for Hypertext Preprocessor - is a widely used general purpose scripting or programming language. Hypertext Preprocessor is suited for web development in particular as it can be embedded into HTML.

    Read the article

  • Ajax Talk at .NET Developers Association

    - by Stephen Walther
    Thanks everyone who came to my Ajax talk tonight at the .NET Developers Association! The slides and demos from the talk can be downloaded by clicking the following link:   ASP.NET Ajax: What’s New?    You need Visual Studio  2010 to view the code samples. The first project, named Demos, contains the following samples: ASPAjax4 1_CompositeScripts.aspx – Demonstrates how to use the ScriptManger to combine, compress, and cache JavaScript files automatically. 2_EnableCdn.aspx – Demonstrates how to retrieve ASP.NET Ajax framework scripts from the Microsoft Ajax CDN automatically. jQuery 1_Selectors.aspx – Demonstrates how to use jQuery selectors 2_WebForms.aspx – Demonstrates how to use the client tablesorter plugin with ASP.NET Web Forms. 3_MVC.aspx – Demonstrates how to use jQuery animation and the templating plugin with ASP.NET MVC. 4_OData.aspx – Demonstrates how to use jQuery with the Netflix API by using JSONP and odata. 5_Templating.aspx – Demonstrates how to use jQuery client templating. 6_TemplateConditionals.aspx – Demonstrates how to use logic within a jQuery template. 7_DataLinking.aspx – Demonstrates how to perform data-binding in jQuery. 8_Converters.aspx – Demonstrates how to defines converters that work with data-binding. The second project, named ACT_Tools, illustrates how to use the Microsoft Ajax Minifier and the JSBuild JavaScript preprocessor. When you perform a build in Visual Studio, all JavaScript and CSS files are minified automatically. Furthermore, any *.pre.js file is processed using the JSBuild preprocessor and the output is saved to the ScriptOutput folder. Select Show All Files in Visual Studio to see the generated results of the minifier and the preprocessor.

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >