EzDevInfo.com

macros interview questions

Top macros frequently asked interview questions

Strange definitions of TRUE and FALSE macros

I have seen the following macro definitions in a coding book.

#define TRUE  '/'/'/'
#define FALSE '-'-'-'

There was no explanation.

Please explain to me how these will work as TRUE and FALSE.


Source: (StackOverflow)

What's the use of do while(0) when we define a macro? [duplicate]

Possible Duplicate:
Do-While and if-else statements in C/C++ macros

I'm reading the linux kernel and I found many macros like this:

#define INIT_LIST_HEAD(ptr) do { \
    (ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)

Why do they use this rather than define it simply in a {}?


Source: (StackOverflow)

Advertisements

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 preprocessor to find the answer. I feel like having a way of doing this during compilation could be useful.


Source: (StackOverflow)

how to use #ifdef with an OR condition?

Sorry for asking very basic question. I would like to set OR condition in #ifdef directive.? How to do that ? I tried

#ifdef LINUX | ANDROID
...
..
#endif 

It did not work? What is the proper way?


Source: (StackOverflow)

__FILE__ macro shows full path

The standard predefined MACRO __FILE__ available in C shows the full path to the file. Is there any way to short the path? I mean instead of

/full/path/to/file.c

I see

to/file.c

or

file.c

Source: (StackOverflow)

What predefined macro can I use to detect clang?

I'm trying to detect the compiler used to compile my source code. I can easily find predefined macros to check for MSVC or GCC (see http://predef.sourceforge.net/ for example), but I cannot find any macro to check for clang.

Does someone know if clang defines a macro like __CLANG__ in order to know what is currently compiling my code ?


Source: (StackOverflow)

Qt question: What does the Q_OBJECT macro do? Why do all Qt objects need this macro?

I just started using Qt and noticed that all the example class definitions have the macro Q_OBJECT as the first line. What is the purpose of this preprocessor macro?


Source: (StackOverflow)

Where are the recorded macros stored in Notepad++?

I have recorded a macro that I want to share with my work colleague.

In what location are these recorded macros saved, so that I can add it to his machine?

If interested, the macro is for taking a list of values and adding quotes and comma so that it can be used in the WHERE clause of of an SQL query (WHERE x IN ('value1','value2','value3')).


Source: (StackOverflow)

Optional Parameters with C++ Macros

Is there some way of getting optional parameters with C++ Macros? Some sort of overloading would be nice too.


Source: (StackOverflow)

Collection of Great Applications and Programs using Macros

I am very very interested in Macros and just beginning to understand its true power. Please help me collect some great usage of macro systems.

So far I have these constructs:

Pattern Matching:

Andrew Wright and Bruce Duba. Pattern matching for Scheme, 1995

Relations in the spirit of Prolog:

Dorai Sitaram. Programming in schelog. http://www.ccs.neu.edu/home/dorai/schelog/schelog.html

Daniel P. Friedman, William E. Byrd, and Oleg Kiselyov. The Reasoned Schemer. The MIT Press, July 2005

Matthias Felleisen. Transliterating Prolog into Scheme. Technical Report 182, Indiana University, 1985.

Extensible Looping Constructs:

Sebastian Egner. Eager comprehensions in Scheme: The design of SRFI-42. In Workshop on Scheme and Functional Programming, pages13–26, September 2005.

Olin Shivers. The anatomy of a loop: a story of scope and control. In International Conference on Functional Programming, pages 2–14, 2005.

Class Systems:

PLT. PLT MzLib: Libraries manual. Technical Report PLT-TR2006-4-v352, PLT Scheme Inc., 2006. http://www.plt-scheme.org/techreports/

Eli Barzilay. Swindle. http://www.barzilay.org/Swindle.

Component Systems:

Ryan Culpepper, Scott Owens, and Matthew Flatt. Syntactic abstraction in component interfaces. In International Conference on Generative Programming and Component Engineering, pages 373–388, 2005

Software Contract Checking

Matthew Flatt and Matthias Felleisen. Units: Cool modules for HOT languages In ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 236–248, 1998

Oscar Waddell and R. Kent Dybvig. Extending the scope of syntactic abstraction.In Symposium on Principles of Programming Languages, pages 203–215, 199

Parser Generators

Scott Owens, Matthew Flatt, Olin Shivers, and Benjamin McMullan. Lexer and parser generators in Scheme. In Workshop on Scheme and Functional Programming, pages 41–52, September 2004.

Tools for Engineering Semantics:

Matthias Felleisen, Robert Bruce Findler, and Matthew Flatt. Semantics Engineering with PLT Redex. MIT Press, August 2009.

Specifications of Compiler Transformations:

Dipanwita Sarkar, Oscar Waddell, and R. Kent Dybvig. A nanopass framework for compiler education. Journal of Functional Programming,15(5):653–667, September 2005. Educational Pearl.

Novel Forms of Execution

Servlets with serializable continuations Greg Pettyjohn, John Clements, Joe Marshall, Shriram Krishnamurthi, and Matthias Felleisen. Continuations from generalized stack inspection. In International Conference on Functional Programming, pages216–227, 2005.

Theorem-Proving System

Sebastian Egner. Eager comprehensions in Scheme: The design of SRFI-42. In Workshop on Scheme and Functional Programming, pages 13–26, September 2005.

Extensions of the Base Language with Types

Sam Tobin-Hochstadt and Matthias Felleisen.The design and implementation of typed scheme. In Symposium on Principles of Programming Languages, pages 395–406, 2008.

Laziness

Eli Barzilay and John Clements. Laziness without all the hard work:combining lazy and strict languages for teaching. In Functional and declarative programming in education, pages 9–13, 2005.

Functional Reactivity

Gregory H. Cooper and Shriram Krishnamurthi. Embedding dynamic dataflow in a call-by-value language. In European Symposium on Programming, 2006


Reference:

Collected from Ryan Culpepper's Dissertation


Source: (StackOverflow)

Can I record/play Macros in Visual Studio 2012/2013/2015?

Apparently macros were dropped from VS 2012.

Is there a plugin/extension/tool that will let me record & play keyboard macros (much like the record/play temporary macro in VS 2010)?

E.g. I typically would use a macro when converting code from one language to another or to quickly generate properties from a text list, etc.


Source: (StackOverflow)

What makes lisp macros so special

Reading Paul Graham's essays on programming languages one would think that lisp macros are the only way to go. As a busy developer working on other platforms, I have not had the privilege of using lisp macros. As someone who wants to understand the buzz, please explain what makes this feature so powerful.

Please also relate this to something I would understand from the world of python, java, c#, c development.


Source: (StackOverflow)

Is there a Macro Recorder for Eclipse? [closed]

Anybody know of a good eclipse plugin for recording and playing back macros? I've tried this one, but it didn't do me any good- seemed like it wasn't ready for primetime.

I know about editor templates, but I'm looking for something that I can use to record my keystrokes and then apply multiple times against a wad of text.

This seems like a strange hole in an IDE, am I missing some builtin facility for this?


Source: (StackOverflow)

likely()/unlikely() macros in the Linux kernel - how do they work? What's their benefit?

I've been digging through some parts of the Linux kernel, and found calls like this:

if (unlikely(fd < 0))
{
    /* Do something */
}

or

if (likely(!err))
{
    /* Do something */
}

I've found the definition of them:

#define likely(x)       __builtin_expect((x),1)
#define unlikely(x)     __builtin_expect((x),0)

I know that they are for optimization, but how do they work? And how much performance/size decrease can be expected from using them? And is it worth the hassle (and losing the portability probably) at least in bottleneck code (in userspace, of course).


Source: (StackOverflow)

Saving vim macros

Does anyone know how to properly save/reuse macros recorded inside of a vim editor?


Source: (StackOverflow)