I am trying to add a preprocessor definition so that a value is only defined while a certain project is building, then it becomes undefined. I have gone into my project properties -> preprocessor -> preprocessor definitions. In here, I typed #define PROJECTNAME_EXPORT, in hopes that I could call #ifdef PROJECTNAME_EXPORT throughout tha...
How can I tell m4's patsubstr to replace all newlines in a string with a space?
I've tried:
patsubst(MULTI_LINE_STR_DEFINE,`\n',` ')
and
patsubst(MULTI_LINE_STR_DEFINE,`\\n',` ')
...
Having seen the advantages of metaprogramming in Ruby and Python, but being bound to lower-level languages like C++ and C for actual work, I'm thinking of manners by which to combine the two. One instance comes in the simple problem for sorting lists of arbitrary structures/classes. For instance:
struct s{
int a;
int b;
};
vector<s...
Hi. I wish to make a cosine table at compile time. Is there a way to do this without hard coding anything?
...
The __FILE__ and __LINE__ macros are built into the C Pre-Processor, and are often used for printing debug output with file names and line numbers. I need something similar, but with just the name of the directory at the end of the path. For instance if my code is in:
/home/davidc/some/path/to/some/code/foo/bar I need a macro that will j...
I'd like to code in some preprocessor macros to optionally log some information. For example in the .h
//#define ML_DEBUG(x) (x) // flip this bit to do the error logging
#define ML_DEBUG(x) (1==1) // flip this bit to silence
in the .m I implement like:
ML_DEBUG(NSLog(@"Class dealloc: %@", [NSString stringWithCString:object_getClass...
Is there any difference between
#include "./test.h"
and
#include "test.h" for C/C++ preprocessor?
...
I understand that sizeof is an operator, which is evaluated at compile time to an integer constant.
But it seem it can not be used in the #if preprocessor directive like:
#if 4 == sizeof(int)
typedef int Int32;
#endif
(cygwin-gcc 3.4.4 as well as Visual C++ 6.0 report compile errors)
Why is such usage not allowed?
...
Hi,
I was reading some code written in C this evening, and at the top of
the file was the function-like macro HASH:
#define HASH(fp) (((unsigned long)fp)%NHASH)
This left me wondering, why would somebody choose to implement a
function this way using a function-like macro instead of implementing
it as a regular vanilla C function? Wha...
The question is quite clear I think. I'm trying to write a compiler detection header to be able to include in the application information on which compiler was used and which version.
This is part of the code I'm using:
/* GNU C Compiler Detection */
#elif defined __GNUC__
#ifdef __MINGW32__
#define COMPILER "MinGW GCC %d.%...
I have a need to look at the files Xcode will compile before the preprocessor gets a stab at them. In short, I need to stick a preprocessor in front of the preprocessor.
All the Google searching has netted me nada when it comes to details on how to run the default Xcode build process for C-based files after modifying the build rule for ...
Hello everyone!
I have an own annotation processor (let's call it MyProcessor) and a project (let's call it MyProject) which uses the processor by
passing -processor to javac.
Now I need MyProcessor to produce some output and make it available for MyProject.
I have following options (and problems):
Let MyProcessor write a file to th...
I occasionally write code something like this:
// file1.cpp
#define DO_THIS 1
#if DO_THIS
// stuff
#endif
During the code development I may switch the definition of DO_THIS between 0 and 1.
Recently I had to rearrange my source code and copy some code from one file to another. But I found that I had made a mistake and the two par...
Trying to create a macro which can be used for print debug messages when DEBUG is defined, like the following pseudo code:
#define DEBUG 1
#define debug_print(args ...) if (DEBUG) fprintf(stderr, args)
How is this accomplished with a macro?
...
Is there a standalone C++ preprocessor? I don't need the compiler/linker, and I'm not able to install a full kit.
I'd like to be able to obtain preprocessed version of some headers, using some defines and include paths I provide.
EDIT: I can't rely on anything being available. No cl, no gcc, nothing. The least I would need done is some...
Hi,
I'm attempting to use the #define directive to change all of "ulong" to "unsigned long".
Here is an example:
#define ulong unsigned long
ulong idCounter = 0;
Sadly, I think it ends up replacing ulong with "unsigned", rather than "unsigned long". I tried "#define ulong (unsigned long)", but that didn't worth either.
...
I need to have some lines of code "active" in debug mode only, and ignored in release mode.
Is there a way to do something like this:
#include <iostream>
using namespace std;
#ifdef _TEST_
#define _cerr cerr
#else
#define _cerr // cerr
#endif
int main() {
_cerr << "TEST message" << endl;
}
So that when _TEST_ is not defined, some...
what is a##b & #a?
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
main()
{
printf("%s\n",h(f(1,2))); //how should I interpret this?? [line 1]
printf("%s\n",g(f(1,2))); //and this? [line 2]
}
How does this program work?
the output is
12
f(1, 2)
now I understand how a##b & #a work. But...
I have a macro for a character string as follows:
#define APPNAME "MyApp"
Now I want to construct a wide string using this macro by doing something like:
const wchar_t *AppProgID = APPNAME L".Document";
However, this generates a "concatenating mismatched strings" compilation error.
Is there a way to convert the APPNAME macro to a ...
Hi,
I would like to be able to register my classes within a std::map or a vector, don't think about duplicates and such for now.
but I don't want to register it within the class constructor call or any within function of the class, somehow do it outside the class so even if I never instanciate it, I would be able to know that it exists....