I want to write preprocessor functions/arrays that are evaluated at
compile time. For example, if I define
#define MYARR[] {5,4,3,2,1,0}
then, the code
int x = R[0];
should be presented as
int x = 5;
to the compiler. (of course only literals can be used in the index).
This is important if code size/memory is critical and we dont...
I was wondering if there is some standardised way of getting type sizes in memory at the pre-processor stage - so in macro form, sizeof() does not cut it.
If their isn't a standardised method are their conventional methods that most IDE's use anyway?
Are there any other methods that anyone can think of to get such data?
I suppose I co...
Hi,
Very basic question coming up. I wonder why the name after the #ifndef directive is always all caps and don't seem to match the name of the actual header file. What are the rules surrounding this? I've been looking around the webs but, I haven't found any explanation for this. If my header file is called myheader.h would it then be ...
What is the difference (if any) between the two following preprocessor control statements.
#if
and
#ifdef
...
I have the following macro:
#define IF_TRACE_ENABLED(level) if (IsTraceEnabled(level))
The user code should look following:
IF_TRACE_ENABLED(LEVEL1)
{
... some very smart code
}
The emphasis here on curly brackets - I want to prevent "if" from macro to "eat" other code:
if (...)
IF_TRACE_ENABLED(LEVEL1)
printf(....);...
Hi,
I'm learning the boost preprocessor library (because i need to use it), and I wanted to try the file iteration mechanism. I've set up a minimal project with a.cpp and b.hpp. What I'm trying to do is including many time b.hpp via the boost pp :
#include <boost/preprocessor/iteration/iterate.hpp>
#define BOOST_PP_ITERATION_LIMITS (0...
I would like to be able to do something like
#print "C Preprocessor got here!"
for debugging purposes. What's the best / most portable way to do this?
...
I have an application which needs to define indexes in various .h files in a heirarchical manor. There is a large set of common entries in a single file and a number of variant header files that are pulled in to specific projects.
In file: "base.h"
#define AAA 1
#define BBB 2
#define CCC 3
In many files like: "variant_extend...
Hi all.
How to determine elements count in boost.preprocessor tuple`s ?
Thanks.
...
Is there any macro that can get a text as input like "abc" and by text I literally mean text like the one mentioned not an array or anything else, then extract characters of that text and generate a selective piece of code like ones below at compile time:
first example of a piece of code :
Func1(a);
Func2(b);
Func3(c);
second example ...
Where am I going wrong; I want to define a preprocessor value on the command-line for g++ but it fails. Below is sample code that replicate my problem:
[edit] I'm using:g++ (Debian 4.3.2-1.1) 4.3.2GNU Make 3.81
test.h
#ifndef _test_h_
#define _test_h_
#include "iostream"
#if defined(MY_DEFINED_VALUE)
#if (MY_DEFINED_VALUE != 5)
#und...
GCC complains if i do this:
#define M(obj,met, ..., contents) obj##_##met(const void * self, __VA_ARGS__) { \
contents \
}
Giving me these 2 reasons:
error: missing ')' in macro parameter list
warning: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro
Apparently, C99 - style variadic macros expect the clos...
How to trigger C-preprocessor error about missing definition at #if?
I'm using LLVM/Clang/Xcode.
This code works.
#define AAAAA 1
#if AAAAA
#endif
And I expected this code will be an error for undefined symbol.
//#define AAAAA 1 Removed definition.
#if AAAAA
#endif
But it did not. Is this standard/regular behavior? And is ther...
Hi,
i want to replace a
#define INTERVAL_MASK(b) (1 << (b))
with a inline function.
int INTERVAL_MASK(int b)
{
return (1 << b);
}
But i have a switch case, which uses the preprocessor directive in case statements. How to go about converting this? Replacing the switch with if is the only option?
Thanks,
gokul.
...
I am building an application that consists of both a windows driver written in C and a user mode executable in c++. They both use a shared header file to define several macros, constants, enums, etc. In the c++ version, I want to include everything within a namespace, which a feature not supported by the c compiler. Is there certain v...
Given an compile-time constant integer (an object, not a macro), can I combine it with a string literal at compile time, possibly with the preprocessor?
For example, I can concatenate string literals just by placing them adjacent to each other:
bool do_stuff(std::string s);
//...
do_stuff("This error code is ridiculously long so I am g...
I had found a strange output when I write the following lines in very simple way:
Code:
printf("LOL??!\n");
printf("LOL!!?\n");
Output:
It happens even the code is compiled under both MBCS and UNICODE.
The output varies on the sequence of "?" and "!"...
Any idea?
...
Does Eclipse CDT Helios have some handy way to view the the macro expansions after the preprocessor has visited the project files?
...
From a native, external library, I get a header file with enum declarations:
#define LIST(declare) \
declare(A, "aaa") \
declare(B, "bbb") \
declare(C, "ccc") \
Using it, I create a .NET enum:
#define EXTRACT(p1,p2) p1,
enum class Val { LIST(EXTRACT) };
Which works great. The result is Val.A, ... values. Now, I would like...
For my logging I wanted the ability to macro out the statements at compile time, so -define to the rescue!
For my compiler flags I'm compiling with erlc -DFOO, is there a way for -ifdef to determine the difference between FOO = ok, FOO/0, and FOO/1?
-module(foo).
-define(FOO, ok).
-define(FOO(X), io:format("~p~n", [X])).
-export([tes...