Search Results

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

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

  • C/C++ line number

    - by Betamoo
    In the sake of debugging purposes, can I get the line number in C/C++ compilers? (standard way or specific ways for certain compilers) e.g if(!Logical) printf("Not logical value at line number %d \n",LineNumber); // How to get LineNumber without writing it by my hand?(dynamic compilation) Thanks

    Read the article

  • C++ conditional compilation

    - by Shaown
    I have the following code snippet #ifdef DO_LOG #define log(p) record(p) #else #define log(p) #endif void record(char *data){ ..... ..... } Now if I call log("hello world") in my code and DO_LOG isn't defined, will the line be compiled, in other words will it eat up the memory for the string "hello world"? P.S. There are a lot of record calls in the program and it is memory sensitive, so is there any other way to conditionally compile so that it only depends on the #define DO_LOG? Thanks in advance.

    Read the article

  • Why the output for "a" is -80?

    - by Abhi
    #include<stdio.h> #include<conio.h> #define ABC 20 #define XYZ 10 #define XXX ABC - XYZ void main() { int a; a = XXX * 10; printf("\n %d \n", a); getch(); } I thought the output should be 100 but when i saw the result i found o/p as -80. when i put bracket as #define XXX (ABC-XYZ) then i get output as 100 but without bracket i get o/p as -80.

    Read the article

  • C++: Can a macro expand "abc" into 'a', 'b', 'c'?

    - by Peter Alexander
    I've written a variadic template that accepts a variable number of char parameters, i.e. template <char... Chars> struct Foo; I was just wondering if there were any macro tricks that would allow me to instantiate this with syntax similar to the following: Foo<"abc"> or Foo<SOME_MACRO("abc")> or Foo<SOME_MACRO(abc)> etc. Basically, anything that stops you from having to write the characters individually, like so Foo<'a', 'b', 'c'> This isn't a big issue for me as it's just for a toy program, but I thought I'd ask anyway.

    Read the article

  • SASS mixin for swapping images / floats on site language (change)

    - by DBUK
    Currently using SASS on a website build. It is my first project using it, tried a little LESS before and liked it. I made a few basic mixins and variables with LESS, super useful stuff! I am trying to get my head around SASS mixins, and syntax, specifically for swapping images when the page changes to a different language, be that with body ID changing or <html lang="en">. And, swapping floats around if, for example, a website changed to chinese. So a mixin where float left is float left unless language is AR and then it becomes float right. With LESS I think it would be something like: .headerBg() when (@lang = en) {background-image:url(../img/hello.png);} .headerBg() when (@lang = it) {background-image:url(../img/ciao.png);} .header {.headerBg(); width: 200px; height:100px} .floatleft() when (@lang = en) { float: left;} .floatleft() when (@lang = ar) { float: right;} .logo {.floatleft();} Its the syntax I am having problems with combined with a brain melting day.

    Read the article

  • Returning pointer to a certain value in a macro?

    - 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 use the compile time constant __LINE__ in a string?

    - by John
    I can use __LINE__ as a method parameter just fine, but I would like an easy way to use it in a function that uses strings. For instance say I have this: 11 string myTest() 12 { 13 if(!testCondition) 14 return logError("testcondition failed"); 15 } And I want the result of the function 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

  • best practice when referring to a program's name in C

    - by guest
    what is considered best practice when referring to a program's name? i've seen #define PROGRAM_NAME "myprog" printf("this is %s\n", PROGRAM_NAME); as well as printf("this is %s\n", argv[0]); i know, that the second approach will give me ./myprog rather than myprog when the program is not called from $PATH and that the first approach will guarantee consistence regarding the program's name. but is there anything else, that makes one approach superior to the other?

    Read the article

  • Macros in C.... please give the solution

    - by Jungle_hacker
    suppose i declared a macro name anything, xyz() and now i am creating another macro xyz1() and referencing the 1st macro i.e xyz() in 2nd. finally i'll create another macro xyz2() and referencing 2nd macro in 3rd... now my question is is this correct(its executing without any problem)..? and macro xyz() is defined twice.... why its not giving error ? what is the solution..?

    Read the article

  • error: expected ',' or '...' before numeric constant

    - by goldfrapp04
    Just a Qt Gui Application with QDialog as the Base Class, the simplest type you can expect. I've programmed on Qt for several times but this is the first time I meet this problem... I've added minimal code to the program, and here's the code in dialog.h (which is mostly automatically generated) #ifndef DIALOG_H #define DIALOG_H #include <QDialog> #include <QPixmap> #include "bmp.h" namespace Ui { class Dialog; } class Dialog : public QDialog { Q_OBJECT public: explicit Dialog(QWidget *parent = 0); ~Dialog(); private slots: void on_openButton_clicked(); private: Ui::Dialog *ui; BMP srcImage; QImage compressedImage[3]; }; #endif // DIALOG_H While I edit, the "public:" is underlined and says "unexpected token '('". When I try to build the program, it says in the line "Q_OBJECT", "error: expected ',' or '...' before numeric constant". I'm sure I've defined nothing related to it (to be exact, I defined an N and an n in file bmp.h, both are int). Any idea of what's wrong here? Thanks.

    Read the article

  • C/C++ pragma in define macro

    - by aaa
    is there some way to embed pragma statement in macro with other statements? I am trying to achieve something like: #define DEFINE_DELETE_OBJECT(type) \ void delete_ ## type_(int handle); \ void delete_ ## type(int handle); \ #pragma weak delete_ ## type_ = delete_ ## type I am okay with boost solutions (save for wave) if one exists. thank you

    Read the article

  • C++: Maybe you know this fitfall?

    - by Martijn Courteaux
    Hi, I'm developing a game. I have a header GameSystem (just methods like the game loop, no class) with two variables: int mouseX and int mouseY. These are updated in my game loop. Now I want to access them from Game.cpp file (a class built by a header-file and the source-file). So, I #include "GameSystem.h" in Game.h. After doing this I get a lot of compile errors. When I remove the include he says of course: Game.cpp:33: error: ‘mouseX’ was not declared in this scope Game.cpp:34: error: ‘mouseY’ was not declared in this scope Where I want to access mouseX and mouseY. All my .h files have Header Guards, generated by Eclipse. I'm using SDL and if I remove the lines that wants to access the variables, everything compiles and run perfectly (*). I hope you can help me... This is the error-log when I #include "GameSystem.h" (All the code he is refering to works, like explained by the (*)): In file included from ../trunk/source/domein/Game.h:14, from ../trunk/source/domein/Game.cpp:8: ../trunk/source/domein/GameSystem.h:30: error: expected constructor, destructor, or type conversion before ‘*’ token ../trunk/source/domein/GameSystem.h:46: error: variable or field ‘InitGame’ declared void ../trunk/source/domein/GameSystem.h:46: error: ‘Game’ was not declared in this scope ../trunk/source/domein/GameSystem.h:46: error: ‘g’ was not declared in this scope ../trunk/source/domein/GameSystem.h:46: error: expected primary-expression before ‘char’ ../trunk/source/domein/GameSystem.h:46: error: expected primary-expression before ‘bool’ ../trunk/source/domein/FPS.h:46: warning: ‘void FPS_SleepMilliseconds(int)’ defined but not used This is the code which try to access the two variables: SDL_Rect pointer; pointer.x = mouseX; pointer.y = mouseY; pointer.w = 3; pointer.h = 3; SDL_FillRect(buffer, &pointer, 0xFF0000);

    Read the article

  • Is there a way to know if std::chrono::monotonic_clock is defined?

    - by Vicente Botet Escriba
    C++0X N3092 states that monotonic_clock is optional. 20.10.5.2 Class monotonic_clock [time.clock.monotonic] 1 Objects of class monotonic_clock represent clocks for which values of time_point never decrease as physical time advances. monotonic_clock may be a synonym for system_clock if system_clock::is_monotonic is true. ** 2 The class monotonic_clock is conditionally supported.** Is there a way using SFINAE or another technique to define a traits class that states if monotonic_clock is defined? struct is_monotonic_clock_defined; If yes, how? If not, shouldn't the standard define macro that gives this information at preprocessing time?

    Read the article

  • Implementation of a C pre-processor in Python or JavaScript?

    - by grrussel
    Is there a known implementation of the C pre-processor tool implemented either in Python or JavaScript? I am looking for a way to robustly pre-process C (and C like) source code and want to be able to process, for example, conditional compilation and macros without invoking an external CPP tool or native code library. Another potential use case is pre-processing within a web application, within the web browser. So far, I have found implementations in Java, Perl, and of course, C and C again. It may be plausible to use one of the C to JavaScript compilers now becoming available. The PLY (Python Lex and Yacc) tools include a cpp implemented in Python.

    Read the article

  • Why are argument substitutions not replaced during rescanning?

    - by James McNellis
    Consider the following macro definitions and invocation: #define x x[0] #define y(arg) arg y(x) This invocation expands to x[0] (tested on Visual C++ 2010, g++ 4.1, mcpp 2.7.2, and Wave). Why? Specifically, why does it not expand to x[0][0]? During macro replacement, A parameter in the replacement list...is replaced by the corresponding argument after all macros contained therein have been expanded. Before being substituted, each argument’s preprocessing tokens are completely macro replaced (C++03 §16.3.1/1). Evaluating the macro invocation, we take the following steps: The function-like macro y is invoked with x as the argument for its arg parameter The x in the argument is macro-replaced to become x[0] The arg in the replacement list is replaced by the macro-replaced value of the argument, x[0] The replacement list after substitution of all the parameters is x[0]. After all parameters in the replacement list have been substituted, the resulting preprocessing token sequence is rescanned...for more macro names to replace (C++03 §16.3.4/1). If the name of the macro being replaced is found during this scan of the replacement list...it is not replaced. Further, if any nested replacements encounter the name of the macro being replaced, it is not replaced (C++03 §16.3.4/2). The replacement list x[0] is rescanned (note that the name of the macro being replaced is y): x is identified as an object-like macro invocation x is replaced by x[0] Replacement stops at this point because of the rule in §16.3.4/2 preventing recursion. The replacement list after rescanning is x[0][0]. I have clearly misinterpreted something since all of the preprocessors I've tested say I am wrong. In addition, this example is a piece of a larger example in the C++0x FCD (at §16.3.5/5) and it too says that the expected replacement is x[0]. Why is x not replaced during rescanning? C99 and C++0x effectively have the same wording as C++03 in the quoted sections.

    Read the article

  • Possible to add an EventListener to a function for Actionscript 3?

    - by Tom
    I'm trying to setup something like Aspect Oriented Programming in Actionscript 3, basically the only thing I need to be able to do is something like this: SomeClass.getMethod("methodName").addEventListener(afterMethodExecuted, function() { //run code }); This way I can run code after (or before) any method in any class has run, allowing numerous new possibilities. How should I implement this?

    Read the article

  • C++ Translation Phase Confusion

    - by blakecl
    Can someone explain why the following doesn't work? int main() // Tried on several recent C++ '03 compilers. { #define FOO L const wchar_t* const foo = FOO"bar"; // Will error out with something like: "identifier 'L' is undefined." #undef FOO } I thought that preprocessing was done in an earlier translation phase than string literal operations and general token translation. Wouldn't the compiler be more or less seeing this: int main() { const wchar_t* const foo = L"bar"; } It would be great if someone could cite an explanation from the standard.

    Read the article

  • Problems with variadic macros in C

    - by imikedaman
    Hi, I'm having a problem with optional arguments in #define statements in C, or more specifically with gcc 4.2: bool func1(bool tmp) { return false; } void func2(bool tmp, bool tmp2) {} #define CALL(func, tmp, ...) func(tmp, ##__VA_ARGS__) int main() { // this compiles CALL(func2, CALL(func1, false), false); // this fails with: Implicit declaration of function 'CALL' CALL(func2, false, CALL(func1, false)); } That's obviously a contrived example, but does show the problem. Does anyone know how I can get the optional arguments to "resolve" correctly? Additional information: If I remove the ## before _VA_ARGS_, and do something like this: bool func2(bool tmp, bool tmp2) { return false; } #define CALL(func, tmp, ...) func(tmp, __VA_ARGS__) int main() { CALL(func2, false, CALL(func2, false, false)); } That compiles, but it no longer works with zero arguments since it would resolve to func(tmp, )

    Read the article

  • Cleanest way to store lists of filter coefficients in a C header

    - by Nick T
    I have many (~100 or so) filter coefficients calculated with the aid of some Matlab and Excel that I want to dump into a C header file for general use, but I'm not sure what the best way to do this would be. I was starting out as so: #define BUTTER 1 #define BESSEL 2 #define CHEBY 3 #if FILT_TYPE == BUTTER #if FILT_ROLLOFF == 0.010 #define B0 256 #define B1 512 #define B2 256 #define A1 467 #define A2 -214 #elif FILT_ROLLOFF == 0.015 #define B0 256 #define B1 512 // and so on... However, if I do that and shove them all into a header, I need to set the conditionals (FILT_TYPE, FILT_ROLLOFF) in my source before including it, which seems kinda nasty. What's more, if I have 2+ different filters that want different roll-offs/filter types it won't work. I could #undef my 5 coefficients (A1-2, B0-2) in that coefficients file, but it still seems wrong to have to insert an #include buried in code.

    Read the article

  • Where do I put all these function-like #defines, in C?

    - by Tristan
    I'm working with an embedded system, and I'm ending up with a ton of HW-interfacing #define functions. I want to put all of these into a separate file (for OOP-ness), but I don't know the best way to #include that. Do I just put them all into a .c file, then include that? Seems silly to put these in a .h file.

    Read the article

  • C macro issue: redefinition of functions / structure

    - by Andrei Ciobanu
    Given the following code (it's a macro that generates code for a list data structure, based on the contained type). list.h #ifndef _LIST_H #define _LIST_H #ifdef __cplusplus extern "C" { #endif #define LIST_TEMPLATE_INIT(type) \ typedef struct __list_s_##type { \ struct __list_s_##type *next; \ type value; \ } __list_##type; \ \ __list_##type * __list_##type##_malloc(type value){ \ __list_##type * list = NULL; \ list = malloc(sizeof(*list)); \ list->value = value; \ return list; \ }\ \ void __list_##type##_free(__list_##type *list){\ __list_##type * back = list;\ while(list=list->next){\ free(back);\ back = list;\ }\ } #define LIST_TYPE(type) __list_##type #define LIST_MALLOC(type,value) __list_##type##_malloc(value) #define LIST_FREE(type,list) __list_##type##_free(list) #define LIST_DATA(list) (list->value) #ifdef __cplusplus } #endif #endif /* _LIST_H */ And here is how the above code works: #include <stdio.h> #include <stdlib.h> #include "list.h" /* * */ LIST_TEMPLATE_INIT(int) int main(int argc, char** argv) { LIST_TYPE(int)* list = NULL; list = LIST_MALLOC(int, 5); printf("%d",LIST_DATA(list)); LIST_FREE(int,list); return (0); } My question, is it possible to somehow be able to call : LIST_TEMPLATE_INIT(int), as many times as I want, in a decentralized fashion ? The current issue with this right now is that calling LIST_TEMPLATE_INIT(int) in another file raise compilation errors (because of function redefinition): Example of error: error: redefinition of ‘struct __list_s_int’

    Read the article

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