I'm wondering about the practical use of #undef in C. I'm working through K&R, and am up to the preprocessor. Most of this was material I (more or less) understood, but something on page 90 (second edition) stuck out at me:
Names may be undefined with #undef,
usually to ensure that a routine is
really a function, not a macro:
...
As mentioned in many of my previous questions, I'm working through K&R, and am currently into the preprocessor. One of the more interesting things -- something I never knew before from any of my prior attempts to learn C -- is the ## preprocessor operator. According to K&R:
The preprocessor operator ##
provides a way to concatenate...
I can't believe I am asking this...
It has been a while since I used VC6. I set up what I thought was the correct way to include additional directories for include files (I removed another developer's hard coded paths) and put in something like:
%MY_DIR%\include
but this does not work. Am I missing something? Did VC6 not allow this...
I'm looking for a way to convert a preprocessor token to a string.
Specifically, I've somewhere got:
#define MAX_LEN 16
and I want to use it to prevent buffer overrun:
char val[MAX_LEN+1]; // room for \0
sscanf(buf, "%"MAX_LEN"s", val);
I'm open to other ways to accomplish the same thing, but standard library only.
...
In Xcode, I can edit my preprocessor macros in the project settings. I want to create a macro that refers to an environment variable. Basically, I want to be able to refer to $SRC_ROOT in my code. What I currently have in my macros is:
SRC_ROOT=${SRC_ROOT}
but it isn't working.
...
I want to implement the solution using the pre-processor described here:
http://stackoverflow.com/questions/100854/reuse-define-statement-from-h-file-in-c-code
Bonus points if you can point me to the docs at MSDN. I'm having trouble finding them...
...
I have three closely related applications that are build from the same source code - let's say APP_A, APP_B, and APP_C. APP_C is a superset of APP_B which in turn is a superset of APP_A.
So far I've been using a preprocessor define to specify the application being built, which has worked like this.
// File: app_defines.h
#define APP_A ...
A basic definition and example and a few references for "X-Macros" is given in this wikipedia entry on the C pre-processor:
An X-Macro is a header file (commonly
using a ".def" extension instead of
the traditional ".h") that contains a
list of similar macro calls (which can
be referred to as "component macros").
What are s...
I wonder if there is a way to set the value of #define in run time.
I assume that there is a query for Oracle specific and Sql Server specific at the code below.
#define oracle
// ...
#if oracle
// some code
#else
// some different code.
#endif
...
Let's say I have a source file with many preprocessor directives . Is it possible to see how it looks after the preprocessor is done with it ?
...
I have a C/C++ source file with conditional compilation. Before I ship it to customers I want to remove most of the #if statements, so that my customers do not need to worry about passing the right -D options to the compiler.
I have this implemented and working in Python, but it only handles #ifdef and #ifndef statements properly. I n...
Suppose I have #define foo in various header files. It may expand to some different things. I would like to know (when compiling a .cc file) when a #define is encountered, to what it will expand, it which file it is and where it got included from.
Is it possible? If not, are there any partial solutions that may help?
Feel free to add c...
How can I tell the preprocessor not to replace a specific macro?
The specific problem is the following: Windows header files define the GetMessage macro.
My C++ header files with my API have a GetMessage method. I do not want to rename my method. But when using the API on Windows, including windows.h replaces my GetMessage method call ...
Im looking to use:
#define
and
#if
to allow me to simulate potentially absent hardware during unit tests. What are the rules for useing the #define statements?
i.e. what is its default scope? can I change the scope of the directive?
...
I am asking this question from an educational/hacking point of view, (I wouldn't really want to code like this).
Is it possible to implement a while loop only using C preprocessor directives. I understand that macros cannot be expanded recursively, so how would this be accomplished?
Thanks
...
UPDATE:
Obviously, you'd want to do this using templates or a base class rather than macros. Unfortunately for various reasons I can't use templates, or a base class.
At the moment I am using a macro to define a bunch of fields and methods on various classes, like this:
class Example
{
// Use FIELDS_AND_METHODS macro to define some...
Is it possible to set a symbol for conditional compilation by setting up properties in an Xcode project?
My aim is to to create a symbol that is available to all files, without having to use import/include, so that a set of common classes can have a special behavior in some projects. Like the following, but with my own symbols.
#if TAR...
Are C-style macro names subject to the same naming rules as identifiers? After a compiler upgrade, it is now emitting this warning for a legacy application:
warning #3649-D: white space is required between the macro name "CHAR_" and its replacement text
#define CHAR_& 38
This line of code is defining an ASCII value c...
Is there a way to (ab)use the C preprocessor to emulate namespaces in C?
I'm thinking something along these lines:
#define NAMESPACE name_of_ns
some_function() {
some_other_function();
}
This would get translated to:
name_of_ns_some_function() {
name_of_ns_some_other_function();
}
...
I'm interested in using something other than the C preprocessor to preprocess my C and Objective-C source code. Are there good alternatives?
An example would be something that allowed one to escape out into a python or perl snippet in the middle of C code, and where the snippet spit out C that is then compiled as normal.
...