Search Results

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

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

  • Creating serializeable unique compile-time identifiers for arbitrary UDT's.

    - by Endiannes
    I would like a generic way to create unique compile-time identifiers for any C++ user defined types. for example: unique_id<my_type>::value == 0 // true unique_id<other_type>::value == 1 // true I've managed to implement something like this using preprocessor meta programming, the problem is, serialization is not consistent. For instance if the class template unique_id is instantiated with other_type first, then any serialization in previous revisions of my program will be invalidated. I've searched for solutions to this problem, and found several ways to implement this with non-consistent serialization if the unique values are compile-time constants. If RTTI or similar methods, like boost::sp_typeinfo are used, then the unique values are obviously not compile-time constants and extra overhead is present. An ad-hoc solution to this problem would be, instantiating all of the unique_id's in a separate header in the correct order, but this causes additional maintenance and boilerplate code, which is not different than using an enum unique_id{my_type, other_type};. A good solution to this problem would be using user-defined literals, unfortunately, as far as I know, no compiler supports them at this moment. The syntax would be 'my_type'_id; 'other_type'_id; with udl's. I'm hoping somebody knows a trick that allows implementing serialize-able unique identifiers in C++ with the current standard (C++03/C++0x), I would be happy if it works with the latest stable MSVC and GNU-G++ compilers, although I expect if there is a solution, it's not portable.

    Read the article

  • Separate specific #ifdef branches

    - by detly
    In short: I want to generate two different source trees from the current one, based only on one preprocessor macro being defined and another being undefined, with no other changes to the source. If you are interested, here is my story... In the beginning, my code was clean. Then we made a new product, and yea, it was better. But the code saw only the same peripheral devices, so we could keep the same code. Well, almost. There was one little condition that needed to be changed, so I added: #if defined(PRODUCT_A) condition = checkCat(); #elif defined(PRODUCT_B) condition = checkCat() && checkHat(); #endif ...to one and only one source file. In the general all-source-files-include-this header file, I had: #if !(defined(PRODUCT_A)||defined(PRODUCT_B)) #error "Don't make me replace you with a small shell script. RTFM." #endif ...so that people couldn't compile it unless they explicitly defined a product type. All was well. Oh... except that modifications were made, components changed, and since the new hardware worked better we could significantly re-write the control systems. Now when I look upon the face of the code, there are more than 60 separate areas delineated by either: #ifdef PRODUCT_A ... #else ... #endif ...or the same, but for PRODUCT_B. Or even: #if defined(PRODUCT_A) ... #elif defined(PRODUCT_B) ... #endif And of course, sometimes sanity took a longer holiday and: #ifdef PRODUCT_A ... #endif #ifdef PRODUCT_B ... #endif These conditions wrap anywhere from one to two hundred lines (you'd think that the last one could be done by switching header files, but the function names need to be the same). This is insane. I would be better off maintaining two separate product-based branches in the source repo and porting any common changes. I realise this now. Is there something that can generate the two different source trees I need, based only on PRODUCT_A being defined and PRODUCT_B being undefined (and vice-versa), without touching anything else (ie. no header inclusion, no macro expansion, etc)?

    Read the article

  • Opening Macro definitions: tdfx_span.c: lvalue required as left operand of assignment

    - by anttir
    Hi, I'm trying to compile X11R6-7.0 under Ubuntu maverick and got some weird compilation errors I'm unable to resolve myself. I needed X11R6-7.0 as ati catalyst drivers don't support newer xorg and oss drivers don't support 3d acceleration of my hardware. Anyone know what this error message means? I know some C but I got a bit confused. Does it mean GET_FB_DATA macro returned NULL or some method/property not set? Any further insight how to "debug" preprocessor definitions at this point would be great. I don't think I can print anything useful with #error. The error I get: tdfx_span.c: In function ‘tdfxDDWriteDepthPixels’: tdfx_span.c:976: error: lvalue required as left operand of assignment tdfx_span.c:1008: error: lvalue required as left operand of assignment tdfx_span.c: In function ‘write_stencil_pixels’: tdfx_span.c:1242: error: lvalue required as left operand of assignment the Code: 958- switch (depth_size) { 959- case 16: 960- GetBackBufferInfo(fxMesa, &backBufferInfo); 961- /* 962- * Note that the _LOCK macro adds a curly brace, 963- * and the UNLOCK macro removes it. 964- */ 965- WRITE_FB_SPAN_LOCK(fxMesa, info, 966- GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); 967- { 968- LFBParameters ReadParams; 969- GetFbParams(fxMesa, &info, &backBufferInfo, 970- &ReadParams, sizeof(GLushort)); 971- for (i = 0; i < n; i++) { 972- if (mask[i] && visible_pixel(fxMesa, x[i], y[i])) { 973- xpos = x[i] + fxMesa->x_offset; 974- ypos = bottom - y[i]; 975- d16 = depth[i]; 976: PUT_FB_DATA(&ReadParams, GLushort, xpos, ypos, d16); 977- } 978- } 979- } 980- WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); 981- break; 982- case 24: And relative macros: #define GET_FB_DATA(ReadParamsp, type, x, y) \ (((x) < (ReadParamsp)->firstWrappedX) \ ? (((type *)((ReadParamsp)->lfbPtr)) \ [(y) * ((ReadParamsp)->LFBStrideInElts) \ + (x)]) \ : (((type *)((ReadParamsp)->lfbWrapPtr)) \ [((y)) * ((ReadParamsp)->LFBStrideInElts) \ + ((x) - (ReadParamsp)->firstWrappedX)])) #define GET_ORDINARY_FB_DATA(ReadParamsp, type, x, y) \ (((type *)((ReadParamsp)->lfbPtr)) \ [(y) * ((ReadParamsp)->LFBStrideInElts) \ + (x)]) #define GET_WRAPPED_FB_DATA(ReadParamsp, type, x, y) \ (((type *)((ReadParamsp)->lfbWrapPtr)) \ [((y)) * ((ReadParamsp)->LFBStrideInElts) \ + ((x) - (ReadParamsp)->firstWrappedX)]) #define PUT_FB_DATA(ReadParamsp, type, x, y, value) \ (GET_FB_DATA(ReadParamsp, type, x, y) = (type)(value)) #define PUT_ORDINARY_FB_DATA(ReadParamsp, type, x, y, value) \ (GET_ORDINARY_FB_DATA(ReadParamsp, type, x, y) = (type)(value)) #define PUT_WRAPPED_FB_DATA(ReadParamsp, type, x, y, value) \ (GET_WRAPPED_FB_DATA(ReadParamsp, type, x, y) = (type)(value)) The LFBParameters Struct 483-typedef struct 484-{ 485- void *lfbPtr; 486- void *lfbWrapPtr; 487- FxU32 LFBStrideInElts; 488- GLint firstWrappedX; 489-} 490:LFBParameters; Thanks for looking.

    Read the article

  • Is there a C pre-processor which eliminates #ifdef blocks based on values defined/undefined?

    - by Jonathan Leffler
    Original Question What I'd like is not a standard C pre-processor, but a variation on it which would accept from somewhere - probably the command line via -DNAME1 and -UNAME2 options - a specification of which macros are defined, and would then eliminate dead code. It may be easier to understand what I'm after with some examples: #ifdef NAME1 #define ALBUQUERQUE "ambidextrous" #else #define PHANTASMAGORIA "ghostly" #endif If the command were run with '-DNAME1', the output would be: #define ALBUQUERQUE "ambidextrous" If the command were run with '-UNAME1', the output would be: #define PHANTASMAGORIA "ghostly" If the command were run with neither option, the output would be the same as the input. This is a simple case - I'd be hoping that the code could handle more complex cases too. To illustrate with a real-world but still simple example: #ifdef USE_VOID #ifdef PLATFORM1 #define VOID void #else #undef VOID typedef void VOID; #endif /* PLATFORM1 */ typedef void * VOIDPTR; #else typedef mint VOID; typedef char * VOIDPTR; #endif /* USE_VOID */ I'd like to run the command with -DUSE_VOID -UPLATFORM1 and get the output: #undef VOID typedef void VOID; typedef void * VOIDPTR; Another example: #ifndef DOUBLEPAD #if (defined NT) || (defined OLDUNIX) #define DOUBLEPAD 8 #else #define DOUBLEPAD 0 #endif /* NT */ #endif /* !DOUBLEPAD */ Ideally, I'd like to run with -UOLDUNIX and get the output: #ifndef DOUBLEPAD #if (defined NT) #define DOUBLEPAD 8 #else #define DOUBLEPAD 0 #endif /* NT */ #endif /* !DOUBLEPAD */ This may be pushing my luck! Motivation: large, ancient code base with lots of conditional code. Many of the conditions no longer apply - the OLDUNIX platform, for example, is no longer made and no longer supported, so there is no need to have references to it in the code. Other conditions are always true. For example, features are added with conditional compilation so that a single version of the code can be used for both older versions of the software where the feature is not available and newer versions where it is available (more or less). Eventually, the old versions without the feature are no longer supported - everything uses the feature - so the condition on whether the feature is present or not should be removed, and the 'when feature is absent' code should be removed too. I'd like to have a tool to do the job automatically because it will be faster and more reliable than doing it manually (which is rather critical when the code base includes 21,500 source files). (A really clever version of the tool might read #include'd files to determine whether the control macros - those specified by -D or -U on the command line - are defined in those files. I'm not sure whether that's truly helpful except as a backup diagnostic. Whatever else it does, though, the pseudo-pre-processor must not expand macros or include files verbatim. The output must be source similar to, but usually simpler than, the input code.) Status Report (one year later) After a year of use, I am very happy with 'sunifdef' recommended by the selected answer. It hasn't made a mistake yet, and I don't expect it to. The only quibble I have with it is stylistic. Given an input such as: #if (defined(A) && defined(B)) || defined(C) || (defined(D) && defined(E)) and run with '-UC' (C is never defined), the output is: #if defined(A) && defined(B) || defined(D) && defined(E) This is technically correct because '&&' binds tighter than '||', but it is an open invitation to confusion. I would much prefer it to include parentheses around the sets of '&&' conditions, as in the original: #if (defined(A) && defined(B)) || (defined(D) && defined(E)) However, given the obscurity of some of the code I have to work with, for that to be the biggest nit-pick is a strong compliment; it is valuable tool to me. The New Kid on the Block Having checked the URL for inclusion in the information above, I see that (as predicted) there is an new program called Coan that is the successor to 'sunifdef'. It is available on SourceForge and has been since January 2010. I'll be checking it out...further reports later this year, or maybe next year, or sometime, or never.

    Read the article

  • What predefined macro can I use to detect clang ?

    - by Pierre Bourdon
    I'm trying to detect the compiler used to compile my source code. I can easily find predefined macros to check for MSVC or GCC (see http://predef.sourceforge.net/ for example), but I cannot find any macro to check for clang. Does someone know if clang defines a macro like __CLANG__ in order to know what is currently compiling my code ?

    Read the article

  • Disable #pragma message("")

    - by Balls-of-steel
    Hi, I needed to include in my project but there is a line, in glut.h which is #pragma message("Note: including lib: glut32.lib\n") It is really annoying and I want to get rid of it when compiling. I could just remove the line in my glut.h but I want my fix to be independent of the glut.h. I have tried setting #pragma warnings to show only critical info, and I have also tried #pragma message disable but nothing worked. Any help?

    Read the article

  • cl.exe Difference in object files when /E output is the same and flags are the same

    - by madiyaan damha
    Hello: I am using Visual Studio 2005's cl.exe compiler. I call it with a bunch of /I /D and some compilation/optimization flags (example: /Ehsc). I have two compilation scripts, and both differ only in the /I flags (include directories are different). All other flags are the same. These scripts produce different object files (and not just a timestamp difference as noted below). The strange thing is that the /E output of both scripts is the same. That means that the include files are not causing the difference in object files, but then again, where is the difference coming from? Can anyone elucidate on how I am seeing two different object files in my situation. If the include files are causing the difference, how come I see identical /E output? PS. The object files are different not only in the timestamp, but in the code sections also. In fact the behavior of my final executable is different in both cases. Edit: PSS: I even looked at the /includeFiles output of cl.exe and that output is identical. The object files, however, differ in more than just the timestamp (in fact, one is 1KB bigger than another!)

    Read the article

  • #if 0 as a define

    - by valerio
    I need a way to define a FLAGS_IF macro (or equivalent) such that FLAGS_IF(expression) <block_of_code> FLAGS_ENDIF when compiling in debug (e.g. with a specific compiler switch) compiles to if (MyFunction(expression)) { <block_of_code> } whereas in release does not result in any instruction, just as it was like this #if 0 <block_of_code> #endif In my ignorance on the matter of c/c++ preprocessors i can't think of any naive way (since #define FLAGS_IF(x) #if 0 does not even compile) of doing this, can you help? I need a solution that: Does not get messed up if */ is present inside <block_of_code> Is sure to generate 0 instructions in release even inside inline functions at any depth (i guess this excludes if (false){<block_of_code>} right?) Is standard compliant if possible Thank you

    Read the article

  • How to keep g++ from taking header file from /usr/include?

    - by WilliamKF
    I am building using zlib.h which I have a local copy to v1.2.5, but in /usr/include/zlib.h there is v1.2.1.2. If I omit adding -I/my/path/to/zlib to my make I get error from using old version which doesn't have Z_FIXED: g++ -g -Werror -Wredundant-decls -D_FILE_OFFSET_BITS=64 -c -o ARCH.linux_26_i86/debug/sysParam.o sysParam.cpp sysParam.cpp: In member function `std::string CSysParamAccess::getCompressionStrategyName() const': sysParam.cpp:1816: error: `Z_FIXED' was not declared in this scope sysParam.cpp: In member function `bool CSysParamAccess::setCompressionStrategy(const std::string&, paramSource)': sysParam.cpp:1849: error: `Z_FIXED' was not declared in this scope Alternatively, if I add the include path to the zlib z1.2.5 I am using, I get double defines, it seems as if the zlib.h is included twice with two different sets of -D values, but I don't see how that is happening: g++ -g -Werror -Wredundant-decls -I../../src/zlib-1.2.5 -D_FILE_OFFSET_BITS=64 -c -o ARCH.linux_26_i86/debug/sysParam.o sysParam.cpp In file included from sysParam.cpp:24: ../../src/zlib-1.2.5/zlib.h:1582: warning: redundant redeclaration of `void* gzopen64(const char*, const char*)' in same scope ../../src/zlib-1.2.5/zlib.h:1566: warning: previous declaration of `void* gzopen64(const char*, const char*)' ../../src/zlib-1.2.5/zlib.h:1583: warning: redundant redeclaration of `long long int gzseek64(void*, long long int, int)' in same scope ../../src/zlib-1.2.5/zlib.h:1567: warning: previous declaration of `off64_t gzseek64(void*, off64_t, int)' ../../src/zlib-1.2.5/zlib.h:1584: warning: redundant redeclaration of `long long int gztell64(void*)' in same scope ../../src/zlib-1.2.5/zlib.h:1568: warning: previous declaration of `off64_t gztell64(void*)' ../../src/zlib-1.2.5/zlib.h:1585: warning: redundant redeclaration of `long long int gzoffset64(void*)' in same scope ../../src/zlib-1.2.5/zlib.h:1569: warning: previous declaration of `off64_t gzoffset64(void*)' ../../src/zlib-1.2.5/zlib.h:1586: warning: redundant redeclaration of `uLong adler32_combine64(uLong, uLong, long long int)' in same scope ../../src/zlib-1.2.5/zlib.h:1570: warning: previous declaration of `uLong adler32_combine64(uLong, uLong, off64_t)' ../../src/zlib-1.2.5/zlib.h:1587: warning: redundant redeclaration of `uLong crc32_combine64(uLong, uLong, long long int)' in same scope ../../src/zlib-1.2.5/zlib.h:1571: warning: previous declaration of `uLong crc32_combine64(uLong, uLong, off64_t)' Here some of the relavent lines from zlib.h referred to above: // This would be line 1558 of zlib.h /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if * both are true, the application gets the *64 functions, and the regular * functions are changed to 64 bits) -- in case these are set on systems * without large file support, _LFS64_LARGEFILE must also be true */ #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); #endif #if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0 # define gzopen gzopen64 # define gzseek gzseek64 # define gztell gztell64 # define gzoffset gzoffset64 # define adler32_combine adler32_combine64 # define crc32_combine crc32_combine64 # ifdef _LARGEFILE64_SOURCE ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); # endif #else ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); #endif // This would be line 1597 of zlib.h I'm not sure how to track this down further. I tried moving the include of zlib.h to the top and bottom of the includes list of the cpp file, but it made no difference. An excerpt of passing -E to g++ shows in part: extern int inflateInit2_ (z_streamp strm, int windowBits, const char *version, int stream_size); extern int inflateBackInit_ (z_streamp strm, int windowBits, unsigned char *window, const char *version, int stream_size); # 1566 "../../src/zlib-1.2.5/zlib.h" extern gzFile gzopen64 (const char *, const char *); extern off64_t gzseek64 (gzFile, off64_t, int); extern off64_t gztell64 (gzFile); extern off64_t gzoffset64 (gzFile); extern uLong adler32_combine64 (uLong, uLong, off64_t); extern uLong crc32_combine64 (uLong, uLong, off64_t); # 1582 "../../src/zlib-1.2.5/zlib.h" extern gzFile gzopen64 (const char *, const char *); extern long long gzseek64 (gzFile, long long, int); extern long long gztell64 (gzFile); extern long long gzoffset64 (gzFile); extern uLong adler32_combine64 (uLong, uLong, long long); extern uLong crc32_combine64 (uLong, uLong, long long); # 1600 "../../src/zlib-1.2.5/zlib.h" struct internal_state {int dummy;}; Not sure why lines 1566 and 1582 are coming out together in the CPP output, but hence the warning about duplicate declarations.

    Read the article

  • C++ classes with members referencing each other

    - by Saad Imran.
    I'm trying to write 2 classes with members that reference each other. I'm not sure if I'm doing something wrong or it's just not possible. Can anyone help me out here... Source.cpp #include "Headers.h" using namespace std; void main() { Network* network = new Network(); system("pause"); return; } Headers.h #ifndef Headers_h #define Headers_h #include <iostream> #include <vector> #include "Network.h" #include "Router.h" #endif Network.h #include "Headers.h" class Network { protected: vector<Router> Routers; }; Router.h #include "Headers.h" class Router { protected: Network* network; public: }; The errors I'm getting are: error C2143: syntax error : missing ';' before '<' error C2238: unexpected token(s) preceding ';' error C4430: missing type specifier - int assumed. I'm pretty sure I'm not missing any semicolons or stuff like that. The program works find if I take out one of the members. I tried finding similar questions and the solution was to use pointers, but that's what I'm doing and it does't seem to be working!

    Read the article

  • How do I inhibit "note C6311" in Microsoft C compiler?

    - by piCookie
    In this maximally clipped source example, the manifest constant FOOBAR is being redefined. This is deliberate, and there is extra code in the live case to make use of each definition. The pragma was added to get rid of a warning message, but then a note appeared, and I don't seem to find a way to get rid of the note. I've been able to modify this particular source to #undef between the #define, but I would like to know if there's a way to inhibit the note without requiring #undef, since there are multiple constants being handled the same way. #pragma warning( disable : 4005 ) // 'identifier' : macro redefinition #define FOOBAR FOO #define FOOBAR BAR The compiler banner and output are as follows Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 Copyright (C) Microsoft Corp 1984-1998. All rights reserved. message.c message.c(3) : note C6311: message.c(2) : see previous definition of 'FOOBAR'

    Read the article

  • Linker, Libraries & Directories Information

    - by m00st
    I've finished both my C++ 1/2 classes and we did not cover anything on Linking to libraries or adding additional libraries to C++ code. I've been having a hay-day trying to figure this out; I've been unable to find basic information linking to objects. Initially I thought the problem was the IDE (Netbeans; and Code::Blocks). However I've been unable to get wxWidgets and GTKMM setup. Can someone point me in the right direction on the terminology and basic information about #including files and linking files in a Cpp application? Basically I want/need to know everything in regards to this process. The difference between .dll, .lib, .o, .lib.a, .dll.a. The difference between a .h and a "library" (.dll, .lib correct?) I understand I need to read the compiler documentation I am using; however all compilers (that I know of) use linker and headers; I need to learn this information. Please point me in the right direction! :] So far on my quest I've found out: Linker links libraries already compiled to your project. .a files are static libraries (.lib in windows) .dll in windows is a shared library (.so in *nix) Thanks

    Read the article

  • c++ variadic macro argument count

    - by chedi
    Hi, is there any way to count the number of argument of a variadic macro, other than this one: #define PP_NARG(...) PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) #define PP_NARG_(...) PP_ARG_N(__VA_ARGS__) #define PP_ARG_N( \ _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \ _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \ _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \ _61,_62,_63,N,...) N #define PP_RSEQ_N() \ 63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40, \ 39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16, \ 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0

    Read the article

  • Determining whether compiling on Windows or other system

    - by NumberFour
    Hi, Im currently developing a cross-platform C application. Is there any compiler macro which is defined only during compilation on Windows, so I can #ifdef some Windows specific #includes? Typical example is selecting between WinSock and Berkeley sockets headers: #ifdef _WINDOWS #include <winsock.h> #else #include <sys/socket.h> #include <netinet/in.h> #include <sys/un.h> #include <arpa/inet.h> #include <netdb.h> #endif So the thing Im looking for is something like that _WINDOWS macro. Thanks for any tips.

    Read the article

  • Why I get errors when I try to out a compiler defined macro using a pragma message?

    - by bogdan
    I would like to know why the Visual C++ compiler gets me an warning/error if I use the following code: #pragma message( "You have " _MSC_FULL_VER ) Here is what I get: error C2220: warning treated as error - no 'object' file generated warning C4081: expected ':'; found ')' The problem reproduces for _MSC_FULL_VER or _MSV_VER but not if I try to use others like __FILE__ or __DATE__. These macros are defined, they are documented on msdn

    Read the article

  • Looking for a good explanation of the table generation macro idiom

    - by detly
    I want to make this clear up front : I know how this trick works, what I want is a link to a clear explanation to share with others. One of the answers to a C macro question talks about the "X macro" or "not yet defined macro" idiom. This involves defining something like: #define MAGIC_LIST \ X(name_1, default_1) \ X(name_2, default_2) \ ... Then to create, say, an array of values with named indices you do: typedef enum { #define X(name, val) name, MAGIC_LIST #undef X } NamedDefaults; You can repeat the procedure with a different #define for X() to create an array of values, and maybe debugging strings, etc. I'd like a link to a clear explanation of how this works, pitched at someone who is passably familiar with C. I have no idea what everyone usually calls this pattern, though, so my attempts to search the web for it have failed thus far. (If there is such an explanation on SO, that'd be fine...)

    Read the article

  • #include in C# (conditional compilation)

    - by HeavyWave
    Is it possible in C# to set such a condition that if the condition is true - compile one file;If condition is false - compile another file? Sort of like #ifdef DEBUG #include Class1.cs #else #include Class2.cs #endif Or possibly set it up in project properties.

    Read the article

  • (Cpp) Linker, Libraries & Directories Information

    - by m00st
    I've finished both my C++ 1/2 classes and we did not cover anything on Linking to libraries or adding additional libraries to C++ code. I've been having a hay-day trying to figure this out; I've been unable to find basic information linking to objects. Initially I thought the problem was the IDE (Netbeans; and Code::Blocks). However I've been unable to get wxWidgets and GTKMM setup. Can someone point me in the right direction on the terminology and basic information about #including files and linking files in a Cpp application? Basically I want/need to know everything in regards to this process. The difference between .dll, .lib, .o, .lib.a, .dll.a. The difference between a .h and a "library" (.dll, .lib correct?) I understand I need to read the compiler documentation I am using; however all compilers (that I know of) use linker and headers; I need to learn this information. Please point me in the right direction! :] Thanks

    Read the article

  • Help with data retrieval MACRO

    - by Andrei Ciobanu
    Hello, given the following structure: struct nmslist_elem_s { nmptr data; struct nmslist_elem_s *next; }; typedef struct nmslist_elem_s nmslist_elem; Where: typedef void* nmptr; Is it possible to write a MACRO that retrieves the data from the element and cast it to the right type: MACRO(type, element) that expands to *((type*)element->data). For example for int, i would need something like this: *((int*)(element->data)) .

    Read the article

  • How to prevent duplicates, macro or something?

    - by blez
    Well, the problem is that I've got a lot of code like this for each event passed to the GUI, how can I shortify this? Macros wont do the work I guess. Is there a more generic way to do something like a 'template' ? private delegate void DownloadProgressDelegate(object sender, DownloaderProgressArgs e); void DownloadProgress(object sender, DownloaderProgressArgs e) { if (this.InvokeRequired) { this.BeginInvoke(new DownloadProgressDelegate(DownloadProgress), new object[] { sender, e }); return; } label2.Text = d.speedOutput.ToString(); } private delegate void DownloadSpeedDelegate(object sender, DownloaderProgressArgs e); void DownloadSpeed(object sender, DownloaderProgressArgs e) { if (this.InvokeRequired) { this.BeginInvoke(new DownloadSpeedDelegate(DownloadSpeed), new object[] { sender, e }); return; } string speed = ""; speed = (e.DownloadSpeed / 1024).ToString() + "kb/s"; label3.Text = speed; }

    Read the article

  • What's the C strategy to "imitate" a C++ template ?

    - by Andrei Ciobanu
    After reading some examples on stackoverflow, and following some of the answers for my previous questions (1), I've eventually come with a "strategy" for this. I've come to this: 1) Have a declare section in the .h file. Here I will define the data-structure, and the accesing interface. Eg.: /** * LIST DECLARATION. (DOUBLE LINKED LIST) */ #define NM_TEMPLATE_DECLARE_LIST(type) \ typedef struct nm_list_elem_##type##_s { \ type data; \ struct nm_list_elem_##type##_s *next; \ struct nm_list_elem_##type##_s *prev; \ } nm_list_elem_##type ; \ typedef struct nm_list_##type##_s { \ unsigned int size; \ nm_list_elem_##type *head; \ nm_list_elem_##type *tail; \ int (*cmp)(const type e1, const type e2); \ } nm_list_##type ; \ \ nm_list_##type *nm_list_new_##type##_(int (*cmp)(const type e1, \ const type e2)); \ \ (...other functions ...) 2) Wrap the functions in the interface inside MACROS: /** * LIST INTERFACE */ #define nm_list(type) \ nm_list_##type #define nm_list_elem(type) \ nm_list_elem_##type #define nm_list_new(type,cmp) \ nm_list_new_##type##_(cmp) #define nm_list_delete(type, list, dst) \ nm_list_delete_##type##_(list, dst) #define nm_list_ins_next(type,list, elem, data) \ nm_list_ins_next_##type##_(list, elem, data) (...others...) 3) Implement the functions: /** * LIST FUNCTION DEFINITIONS */ #define NM_TEMPLATE_DEFINE_LIST(type) \ nm_list_##type *nm_list_new_##type##_(int (*cmp)(const type e1, \ const type e2)) \ {\ nm_list_##type *list = NULL; \ list = nm_alloc(sizeof(*list)); \ list->size = 0; \ list->head = NULL; \ list->tail = NULL; \ list->cmp = cmp; \ }\ void nm_list_delete_##type##_(nm_list_##type *list, \ void (*destructor)(nm_list_elem_##type elem)) \ { \ type data; \ while(nm_list_size(list)){ \ data = nm_list_rem_##type(list, tail); \ if(destructor){ \ destructor(data); \ } \ } \ nm_free(list); \ } \ (...others...) In order to use those constructs, I have to create two files (let's call them templates.c and templates.h) . In templates.h I will have to NM_TEMPLATE_DECLARE_LIST(int), NM_TEMPLATE_DECLARE_LIST(double) , while in templates.c I will need to NM_TEMPLATE_DEFINE_LIST(int) , NM_TEMPLATE_DEFINE_LIST(double) , in order to have the code behind a list of ints, doubles and so on, generated. By following this strategy I will have to keep all my "template" declarations in two files, and in the same time, I will need to include templates.h whenever I need the data structures. It's a very "centralized" solution. Do you know other strategy in order to "imitate" (at some point) templates in C++ ? Do you know a way to improve this strategy, in order to keep things in more decentralized manner, so that I won't need the two files: templates.c and templates.h ?

    Read the article

  • How to inline a function for only release build.

    - by Benjamin
    // common.h // This is foo funtion. It has a body. __inline void foo() { /* something */ } // a.cpp #include "common.h" // for foo function // Call foo // b.cpp #include "common.h" // for foo function // Call foo I would like to inline the foo function only when I build for release. -I dont want to inline functions for Debug build. I tried it but linker errors annoyed me. In this case, foo function's body is defined in common.h header file. so if I just do //common.h #if !defined(_DEBUG) __inline #endif void foo() { /* something */ } I will be met a link error in DEBUG build. Because two modules try to include common.h. I have no idea to solve it. Is it possible?

    Read the article

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