preprocessor

Objective-C use of #import and inheritance

I have a hypothetical UIViewController class named "foo". foo inherits from class bar and class bar #import's "Class A", a class which foo uses extensively. The problem is, when I'm using an instance of class A in foo, I don't get any compiler errors, but I do get a warning for instance, that an instance of Class A does not respond to a ...

__FILE__, __LINE__, and __FUNCTION__ usage in C++

Presuming that your C++ compiler supports them, is there any particular reason not to use __FILE__, __LINE__ and __FUNCTION__ for logging and debugging purposes? I'm primarily concerned with giving the user bad data due - for example, reporting the incorrect line number or function as a result of optimization - or taking a performance h...

Is there a "preprocessor" symbol corresponding to the /unsafe flag?

I'm dealing with a WriteableBitmap in C#. I'm currently using an unsafe code block to directly access the pixels via WriteableBitmap.BackBuffer. I'd rather depend on the /unsafe option, however, so I'm considering using WriteableBitmap.WritePixels instead. Is there some way of conditionally compiling in the "unsafe" version such that ...

How can I create different DLLs in one project?

I have a question I don't know if it can be solved. I have one C# project on Visual Studio 2005 and I want to create different DLL names depending on a preprocessor constant. What I have in this moment is the preprocessor constant, two snk files and two assembly's guid. I also create two configurations (Debug and Debug Preprocessor) and ...

C preprocessors

How can I write a program in C which removes all the defined values defined by the user using #define name value? Throughout the program should we replace the name, value? Does anyone have any examples of this? ...

Error Logging C++ Preprocessor Macros __LINE__, __FUNCTION__

I trying to incorporate a simple error logging into my existing app, at the moment it reports errors just using cout so i was hoping to keep a similar interface using the << operator. However i want it to log the line & function the error occurred. But i don't want to have to type __LINE__, __FUNCTION__ every time i need to log. Does any...

What is the point of saying "#define FOO FOO" in C?

I came across some C code where the author uses the following idiom all over the place: typedef __int32 FOO_INT32; #define FOO_INT32 FOO_INT32 What is the point of doing this? Shouldn't the typedef be enough? It is a workaround for some wonky C compilers out there? ...

Pre-Processor directives in C#

I seem to be having trouble with preprocessor directives in c#. I've created a Visual Studio 2008 C# win forms app. I add this: #if (DEBUG) textBox1.Text = "in debug mode"; #else textBox1.Text = "in release mode"; #endif And when i run in debug i see the expected "in debug mode". However when i switch to Rel...

#include directive: relative to where?

I have looked in The C++ Programming Language to try to find the answer to this. When I #include "my_dir/my_header.hpp" in a header, where does it look for this file? Is it relative to the header, relative to the source file that included it, or something else? ...

What is the worst real-world macros/pre-processor abuse you've ever come across?

What is the worst real-world macros/pre-processor abuse you've ever come across (please no contrived IOCCC answers *haha*)? Please add a short snippet or story if it is really entertaining. The goal is to teach something instead of always telling people "never use macros". p.s.: I've used macros before... but usually I get rid of the...

Macros and Visual C++

I'm trying to get a better understanding of what place (if any) Macros have in modern C++ and Visual C++, also with reference to Windows programming libraries: What problem (if any) do Macros solve in these situations that cannot be solved without using them? I remember reading about Google Chrome's use of WTL for Macros (amonst other t...

What are C macros useful for?

I have written a little bit of C, and I can read it well enough to get a general idea of what it is doing, but every time I have encountered a macro it has thrown me completely. I end up having to remember what the macro is a and substitute it in my head as I read. The ones that I have encountered that were intuitive and easy to understa...

Whats the difference between the WIN32 and _WIN32 defines in c++

I know that WIN32 is obviously to denote win32 compilation but what is the need for _win32? ...

c++ conditional macro evaluation

I have a symbol defined globally that needs to be conditionally undefined for a given subset of my source files. All of the files that require special treatment are already wrapped in pre- and post-inclusions: pre.h: #undefine mysymbol // [1] post.h: #define mysymbol MY_SYMBOL_DEFINITION // [2] My problem is that the pre.h and pos...

Need help rewriting a C macro as a function

Hi, I need some help rewriting the following line in a more type safe way and rewriting it as a function, however the fact that this code is defined inside a function is making it hard for me to think of a clever way of doing it because apparently it would involve declaring several arguments. #define CHECK(id) if(table->cells[id]) isgoo...

C style: Macros or preprocessor?

I've written a library to match strings against a set of patterns and I can now easily embed lexical scanners into C programs. I know there are many well established tools available to create lexical scanners (lex and re2c, to just name the first two that come to mind) this question is not about lexers, it's about the best approach to "...

C#: Declare preprocesor symbol (like DEBUG) globaly for whole project.

Hi, I would like to switch between NUnit and VS Tests like this: #if !NUNIT using Microsoft.VisualStudio.TestTools.UnitTesting; #else using NUnit.Framework; using TestClass = NUnit.Framework.TestFixtureAttribute; using TestMethod = NUnit.Framework.TestAttribute; using TestInitialize = NUnit.Framework.SetUpAttribute; using Test...

C# Macro definitions in Preprocessor

Hi! Is C# able to define Macros like in C with Preprocessor statements to ease regular typing of certain repeating statements like Console.WriteLine("foo"); ? I didn't find a solution. Thanks! ...

To remove #ifdef DEBUG parts for release or not?

Hello, When releasing source code for someone else to see, when coding style is not well defined (no pun intended) do you remove the #ifdef DEBUG parts? (that is the parts that are compiled only when DEBUG is defined) If I remove it, it makes the code looks better (or me look better - do I really want someone to know I've debugged, and...

Is there any cure for the preprocessor blues?

I know that I can kick the the preprocessor to spit out output with the -E option in my particular circumstance. For generated code this preprocessor output is murderous. For example I have a 4gl application and Informix converts this into C which in turn gets spit out to a horrible ugly mess. What I want is an editor that will allow ...