Which macro to wrap Mac OS X specific code in C/C++

It all depends. Each macro specifies something different in meaning. See: https://developer.apple.com/library/mac/documentation/Porting/Conceptual/PortingUnix/compiling/compiling.html#//apple_ref/doc/uid/TP40002850-SW13 __APPLE__ This macro is defined in any Apple computer. __APPLE_CC__ This macro is set to an integer that represents the version number of the compiler. This lets you distinguish, for example, between compilers based on the same version of GCC, but with different … Read more

Retrieving a c++ class name programmatically

You can use typeid: #include <typeinfo> std::cout << typeid(obj).name() << “\n”; However, the type name isn’t standardided and may differ between different compilers (or even different versions of the same compiler), and it is generally not human readable because it is mangled. On GCC and clang (with libstdc++ and libc++), you can demangle names using … Read more

Collection of Great Applications and Programs using Macros

Culpepper & Felleisen, Fortifying Macros, ICFP 2010 Culpepper, Tobin-Hochstadt and Felleisen, Advanced Macrology and the Implementation of Typed Scheme, Scheme Workshop 2007 Flatt, Findler, Felleisen, Scheme with Classes, Mixins, and Traits, APLAS 2006 Herman, Meunier, Improving the Static Analysis of Embedded Languages via Partial Evaluation, ICFP 2004

When should I quote CMake variables?

Two principles of CMake you have to keep in mind: CMake is a script language and arguments are evaluated after the variables are expanded CMake differentiates between normal strings and list variables (strings with semicolon delimiters) Examples set(_my_text “A B C”) with message(“${_my_text}”) would give A B C set(_my_list A B C) with message(“${_my_list}”) would … Read more

What does Q_D macro do in Qt

In short, Qt uses private implementation to manage data. For classes that do this, there usually is an X class and an XPrivate class. The Q_D macro defines the “d” pointer so if you write d->whatever, you have access to that private data part. This article should pretty much cover most of your questions: https://wiki.qt.io/D-Pointer

How to allow optional trailing commas in macros?

Handle both cases You can handle both cases by… handling both cases: macro_rules! define_enum { ($Name:ident { $($Variant:ident,)* }) => { pub enum $Name { None, $($Variant),*, } }; ($Name:ident { $($Variant:ident),* }) => { define_enum!($Name { $($Variant,)* }); }; } define_enum!(Foo1 { A, B }); define_enum!(Foo2 { A, B, }); fn main() {} We’ve … Read more

Macros in Swift?

In this case you should add a default value for the “macro” parameters. Swift 2.2 and higher func log(message: String, function: String = #function, file: String = #file, line: Int = #line) { print(“Message \”\(message)\” (File: \(file), Function: \(function), Line: \(line))”) } log(“Some message”) Swift 2.1 and lower func log(message: String, function: String = __FUNCTION__, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)