107
голосов
2ответов
61724 просмотров

Creating C macro with ## and __LINE__ (token concatenation with positioning macro)

I want to create a C macro that creates a function with a name based on the line number. I thought I could do something like (the real function would have statements within the braces): #define UNIQUE static void Unique_##__LINE__(void) {} Which I hoped would expand to something like: static ...

1
голосов
4ответов
1943 просмотров

Custom C++ Preprocessor / Typeful Macros

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:...

10
голосов
5ответов
980 просмотров

How Does Static Typing Limit Macros?

I was reading Paul Graham's "The Hundred-Year Language" article. http://www.paulgraham.com/hundred.html In there he makes a claim that static typing "preclude[s] true macros". For example, types seem to be an inexhaustible source of research papers, despite the fact that static typing...

2
голосов
5ответов
589 просмотров

Are these placement new macros correct?

I made a couple macros to make using placement new a bit easier. I was just wondering if there were any obvious cases where these would not work. Thanks. #define CONSTRUCT_INPLACE(TYPE,STORAGE,INIT) ::new((TYPE*)STORAGE) TYPE INIT #define DESTRUCT_INPLACE(TYPE,STORAGE) ((TYPE*)STORAG...

9
голосов
3ответов
7148 просмотров

Pros and Cons of Different macro function / inline methods in C

According to the C FAQ, there are basically 3 practical methods for "inlining" code in C: #define MACRO(arg1, arg2) do { \ /* declarations */ \ stmt1; \ stmt2; \ /* ... */ \ } while(0) /* (no trailing ; ) */ or #define FUNC(arg1, arg2) (expr1, expr2, expr3) To cl...

127
голосов
14ответов
111353 просмотров

How do I show the value of a #define at compile-time?

I am trying to figure out what version of Boost my code thinks it's using. I want to do something like this: #error BOOST_VERSION but the preprocessor does not expand BOOST_VERSION. I know I could print it out at run-time from the program, and I know I could look at the output of the preproces...

2
голосов
4ответов
4005 просмотров

Can I substitute __func__ into an identifier name in a C macro?

I'd like to write a C macro which takes this: int foo() { MY_MACRO } and expands it to this: int foo() { _macro_var_foo++; } I've found that I can't use __func__, because that doesn't actually get expanded in the macro; it's treated by the preprocessor like a variable. Is there some wa...

0
голосов
1ответов
141 просмотров

How can avoid having a solution specific hard coded macro in Visual Studio?

Background I have a macro AttachToRemoteProcess that I use to attach the debugger to a running process on a remote computer. The macro use hard coded names for the process and the computer. I use the macro from a toolbar button on a custom toolbar. I consider this a sub par solution and I don't ...

0
голосов
2ответов
158 просмотров

How can I create a macro for getting the library name a class is compiled into?

How can I create a macro for getting the library name a class is compiled into? Is there some way of getting this information from make? Essentially I'd like to do something like: # define LIBRARY_NAME (get info from make maybe?) ... # ifdef LIBRARY_NAME static const char* s_lib...

9
голосов
1ответов
2447 просмотров

C++ template macro shortcut

Often when working with templates, you end up with something like: template <T> class the_class { public: // types typedef T value_type; typedef const value_type const_value_type; typedef value_type& reference; typedef const_value_type& const_reference; typedef ...

2
голосов
4ответов
1110 просмотров

Access a function pointer without parenthesis

I have this code: #include <stdio.h> int getAns(void); int num; int main() { int (*current_ans)(void); current_ans = &getAns; // HERE printf("%d", current_ans()); } int getAns() { return num + 3; } However, is it possible to have something in the // HERE ...

3
голосов
4ответов
320 просмотров

Generating and saving code from Macro

I am analyzing a legacy code which heavily using macro, I am lost in understanding how macro are expanding in code. Could any one suggest me some tool or technique so that I can study actual code generated from macro expansion. Platform : Windows XP Language : C++ Compiler : VC6

0
голосов
1ответов
3259 просмотров

Add header and footer macro

I need to make a difficult makro. When the makro has been activated (will happen via a button), it has to add a header and a footer to the document. Also page1/frontpage needs a different header and footer than all the other potential pages. So far, I have accomplished making page1/frontpage to...

19
голосов
3ответов
9609 просмотров

List of the $(xxx) macro in visual studio

I would like to establish a list of all the visual studio macro that can be used in the post-build event script. $(Configuration) : Name of the current build configuration (ie: Debug or Release).

1
голосов
6ответов
1423 просмотров

#defined bitflags and enums - peaceful coexistence in "c"

I have just discovered the joy of bitflags. I have several questions related to "best-practices" regarding the use of bitflags in C. I learned everything from various examples I found on the web but still have questions. In order to save space, I am using a single 32bit integer field in a struct...

2
голосов
7ответов
4601 просмотров

Stringification on a enumeration member

I need to convert an enumeration member (its value, not the identifier) to a string. I have tried the following, which works for a MACRO (TYPE_A), but not for an enum value (typeA). This is a little bit strange in my opinion. Do you have any idea how to do this? #define _tostr(a) #a #define t...

2
голосов
5ответов
1501 просмотров

What's going on in the 'offsetof' macro?

Visual C++ 2008 C runtime offers an operator 'offsetof', which is actually macro defined as this: #define offsetof(s,m) (size_t)&reinterpret_cast<const volatile char&>((((s *)0)->m)) This allows you to calculate the offset of the member variable m within the class s. What ...

0
голосов
4ответов
3509 просмотров

Highlighting #defined value in VIM

I have XYZ highlighted in the header file where I have defined XYZ. However at the point of where it is used, XYZ is not highlighted. How would I fix this ? I have attached two screen shots (see TH_SYN in the code) to clarify my question- link text Any pointers are welcome.

11
голосов
2ответов
2599 просмотров

XCode 3.2: Changing the default "Code Sense" indentation and whitespaces

I'm working with XCode 3.2 (on "Snow Leopard") which (still) has this nice "Text Macro" auto-completion feature (eg. if you type if it will expand to if (<#condition#>) { <#statements#> }). These macros are also available via "Edit->Insert Text Macro". Unfortunately, the default t...

3
голосов
1ответов
448 просмотров

Learning Scheme Macros. Help me write a define-syntax-rule

I am new to Scheme Macros. If I just have one pattern and I want to combine the define-syntax and syntax-rules, how do I do that? (define-syntax for (syntax-rules (from to) [(for i from x to y step body) ...] [(for i from x to y body) ...])) If I just have one for, how do I combine t...

13
голосов
1ответов
1799 просмотров

visual studio 2008 macro: write to output pane

In a Visual Studio macro, how do you write execution information on the output pane (i.e. the window that usually contains build output)? I'm using Visual Studio 2008, if that is relevant. Solution: I added the following subs to my macro project, I'm posting them here in case they could be usef...

6
голосов
1ответов
4886 просмотров

XCode Preprocessor Macro for Configuration?

I want my XCode Objective-C project to be able to detect which configuration it is being built with. How can I achieve this?

0
голосов
1ответов
5887 просмотров

error C3867: function call missing argument list

I'm upgrading a game engine's source code from Visual Studio 2003 to Visual Studio 2008. When I try and compile the source code I get the following error. error C3867: 'UObject::StaticConstructor': function call missing argument list; use '&UObject::StaticConstructor' to create a pointer ...

8
голосов
5ответов
3439 просмотров

Legit Uses of the offsetof Macro in C / C++

There is this macro offsetof in C/C++ which allows you to get the address offset of a member in a POD structure. For an example from the C FAQ: struct foo { int a; int b; }; struct foo; /* Set the b member of foo indirectly */ *(int *)((char *)foo + offsetof(b)) = 0xDEADBEEF; Now this just ...

4
голосов
1ответов
3794 просмотров

How to delete a macro

I have a macro in Notepad++ that I don't use any more, the macro also uses a shortcut I want to use for other macro's. But there seems to be no function in Notepad++ to delete macro's. Is there a another way to delete macro's in Notepad++ (for instance manipulating the setting-files of Notepad++)?

16
голосов
4ответов
6373 просмотров

C# for writing macros in Visual Studio?

I started C# a while ago and really like it. I work with VS 2008 and really like it. I tried Resharper and loved it. Now I am starting with Macros in VS2008 to increase my coding speed a little more. And stumble upon visual basic. And I do not like that. Is there any way to write macros in C#...

1
голосов
4ответов
3548 просмотров

Set debugging macro conditionally with make

In my C++ project, I have a convention where whenever the macro DEBUG is defined, debugging printf-esque statements are compiled into the executable. To indicate whether or not I want these compiled into the executable, I normally would pass the macro name to gcc with the -Dmacro option. So, in...

2
голосов
2ответов
399 просмотров

sas macro index or other?

I have 169 towns for which I want to iterate a macro. I need the output files to be saved using the town-name (rather than a town-code). I have a dataset (TOWN) with town-code and town-name. Is it possible to have a %let statement that is set to the town-name for each iteration where i=town-cod...

1
голосов
3ответов
460 просмотров

distinguishing between static and non-static methods in c++ at compile time?

For some tracing automation for identifying instances i want to call either: a non-static method of the containing object returning its identifier something else which always returns the same id My current solution is to have a base class with a method which() and a global function which() wh...

3
голосов
1ответов
3677 просмотров

Xcode/GCC predefined macro for target name?

I was wondering if there is an Xcode or GCC preprocessor symbol for the target name of the application. For example if I'm building an application called "MonkeyChicken", is there a preprocessor symbol such that printf( __TARGET_NAME__ ) outputs: MonkeyChicken