Visual Studio macro: Find files that aren’t included in the project?

Here is the C# version of your code: public static void IncludeNewFiles() { int count = 0; EnvDTE80.DTE2 dte2; List<string> newfiles; dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject(“VisualStudio.DTE.10.0”); foreach (Project project in dte2.Solution.Projects) { if (project.UniqueName.EndsWith(“.csproj”)) { newfiles = GetFilesNotInProject(project); foreach (var file in newfiles) project.ProjectItems.AddFromFile(file); count += newfiles.Count; } } dte2.StatusBar.Text = String.Format(“{0} new file{1} included in the … Read more

offsetof at compile time

The offsetof() macro is a compile-time construct. There is no standard-compliant way to define it, but every compiler must have some way of doing it. One example would be: #define offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) ) While not being a compile-time construct technically (see comments by user … Read more

Mathematica: Unevaluated vs Defer vs Hold vs HoldForm vs HoldAllComplete vs etc etc

These are pretty tricky constructs, and it’s tough to give clear explanations; they aren’t as straightforward as Lisp macros (or, for that matter, the relationship between Lisp’s QUOTE and EVAL). However, there’s a good, lengthy discussion available in the form of notes from Robby Villegas’s 1999 talk “Unevaluated Expressions” on Wolfram’s website. Defer is omitted … Read more

Debug Print Macro in C?

I’ve seen this idiom a fair amount: #ifdef DEBUG # define DEBUG_PRINT(x) printf x #else # define DEBUG_PRINT(x) do {} while (0) #endif Use it like: DEBUG_PRINT((“var1: %d; var2: %d; str: %s\n”, var1, var2, str)); The extra parentheses are necessary, because some older C compilers don’t support var-args in macros.

Inline function v. Macro in C — What’s the Overhead (Memory/Speed)?

Calling an inline function may or may not generate a function call, which typically incurs a very small amount of overhead. The exact situations under which an inline function actually gets inlined vary depending on the compiler; most make a good-faith effort to inline small functions (at least when optimization is enabled), but there is … Read more

Problem with Macros

Neil Butterworth, Mark and Pavel are right. SQUARE(++y) expands to ++y * ++y, which increments twice the value of y. Another problem you could encounter: SQUARE(a + b) expands to a + b * a + b which is not (a+b)*(a+b) but a + (b * a) + b. You should take care of adding … Read more