Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [macros]

Macros are used to make a sequence of computing instructions available to the programmer as a single program statement, making the programming task less tedious and less error-prone.[

Filter by
Sorted by
Tagged with
4 votes
4 answers
1k views

For example, for some Xcode projects, if I have some places that defines a number at some .cpp files: const int PAGE_MAX=5; and a new requirement comes that needs to change PAGE_MAX, I need to modify ...
wcminipgasker2023's user avatar
4 votes
1 answer
3k views

I have multiple use cases where I need to call an "entry" function, do a bunch of stuff, and then call an "exit" function. (In my case, "entry" is enabling a chip select ...
fearless_fool's user avatar
-5 votes
2 answers
701 views

I have read from several authors that macros in C should be avoided whenever possible, and use inline functions instead. It's true that inline only 'requests' the compiler to replace the function call ...
Martel's user avatar
  • 615
-1 votes
2 answers
144 views

So, I am making a pure 2D shooter in Unity, and I was thinking about cheats a little bit (Yes, I know that nobody is going to play my game but anyway). I was wondering if you can get pressed keys ...
Peter Veris's user avatar
13 votes
3 answers
3k views

Let's say I want to have several types of output messages in my code. One of them is DEBUG, which is printed only, when the code is compiled in Debug mode. Usually I'd have to write something like #...
Eenoku's user avatar
  • 327
6 votes
4 answers
7k views

I've got a set of classes that all inherit from a base class that are responsible for different functions (sort of like a group of "operators") They all work on the same input and output the same ...
Krupip's user avatar
  • 1,347
1 vote
1 answer
7k views

In some code bases (such as hydra, and thrust's tuple implementation) I see namespaces defined entirely with macros. It appears the reason for this is so that you can configure the namespace to your ...
Krupip's user avatar
  • 1,347
3 votes
1 answer
6k views

Is it generally encouraged or discouraged to create a pre-processor macro in C, that facilitates the creation of many functions with the same signature (differing only in name). For instance, instead ...
Jon Deaton's user avatar
0 votes
1 answer
158 views

I need to make a time profiling for several modules in Fortran, which means, that I'm supposed to write the same code in every beginning and every end of every function. Really, it looks like this: ...
Eenoku's user avatar
  • 327
11 votes
7 answers
4k views

There are some programming languages, like the many dialects of Lisp, that allow for macro-metaprogramming: rewriting and altering sections of code before the code is run. It is relatively trivial to ...
Qqwy's user avatar
  • 4,947
2 votes
3 answers
343 views

Often when I program in C I write the expression for (int i = 0; i < j; i++). I never wrote a macro or a define expression, but could I write a #define to simplify the above expression so that do ...
Niklas Rosencrantz's user avatar
1 vote
1 answer
905 views

I have some platform specific code, such as a string needs different values at different platforms like it: test.cpp #if(PLATFORM==ANDROID) string url="android"; #elif(PLATFORM==IOS) string ...
ggrr's user avatar
  • 5,893
2 votes
1 answer
3k views

In a very simplistic way, I understand: "Compilation" = "Pre-processing" + "Parsing" + "Linking" + "Executable" All the macros and other such pre-processing directives are taken care at the "Pre-...
iammilind's user avatar
  • 2,232
4 votes
2 answers
351 views

I have a bunch of repetitive C++ code that looks like this: // Compute finalOutput if possible. Return true if successful, false otherwise // finalOutput only holds a valid value if true is returned. ...
Thomas Johnson's user avatar
33 votes
2 answers
3k views

The C preprocessor is attached to C, but it has a completely different syntax from the main language: syntactically significant whitespace (end of line terminates a statement, gap after the macro ...
Alex Celeste's user avatar
12 votes
1 answer
2k views

I've heard that Clojure macros are easier to write but not as reliable as Racket's hygienic macros. My question has 2 parts: How does gensym differ from hygienic macros? What do Racket macros provide ...
Alex's user avatar
  • 284
7 votes
3 answers
1k views

As a 'seasoned' Rebol developer with some knowledge of the world outside, I'd be curious as to the utility/pitfalls of implementing Lisp-style macros in Rebol (and/or Red). My understanding (always ...
rgchris's user avatar
  • 365
8 votes
3 answers
1k views

Macros are considered a good thing by one and evil by another. Is there a rule of thumb when to and when not to use macros in C++? When are macros idiomatic and when should they be avoided?
Mast's user avatar
  • 201
22 votes
4 answers
4k views

I'm learning Scheme from the SICP and I'm getting the impression that a big part of what makes Scheme and, even more so, LISP special is the macro system. But, since macros are expanded at compile-...
Elliot Gorokhovsky's user avatar
5 votes
1 answer
3k views

Because there is no language feature in C to protect assignment to global variables would you recommend doing something like this? Take this example: We have a module with the header file called ...
wefwefa3's user avatar
  • 1,007
5 votes
1 answer
2k views

So far I have only done personal projects at home. I hope to get involved in some open source project some time next year. The languages I that have been using the most are C and C++. I have used both ...
wefwefa3's user avatar
  • 1,007
4 votes
1 answer
1k views

Macros exist in many programming languages, for example, C. A data type is a set of values with operations on the values. Are macros values, or data types? Are macros identifiers, variables, or ...
Tim's user avatar
  • 5,555
0 votes
1 answer
855 views

I have noticed that many famous libraries written in Objective-C (eg. AFNetworking) use the macro guard inside their header files. Im aware that the #import directive, which works exactly like #...
maross's user avatar
  • 103
1 vote
1 answer
364 views

In a moderately old blog post, Conal Elliot makes an interesting (if less than serious) argument that C is a purely functional language, by drawing a parallel between the combination of the C ...
Alex Celeste's user avatar
7 votes
1 answer
1k views

On this blog post aphyr (who is a brilliant programmer) states: Clojure macros come with some important restrictions. Because they’re expanded prior to evaluation, macros are invisible to functions. ...
hawkeye's user avatar
  • 4,849
0 votes
2 answers
686 views

I was getting tired of repeating types when writing things like this: NSDictionary* d = @{@"so": [NSNumber numberWithInt:index]), @"much": [NSNumber numberWithBool:accepted]), ...
Craig Gidney's user avatar
20 votes
5 answers
5k views

When looking Python decorators someone made the statement, that they are as powerful as Lisp macros (particularly Clojure). Looking at the examples given in PEP 318 it looks to me as if they are just ...
Profpatsch's user avatar
3 votes
3 answers
2k views

I've read recently that macro support in Scala is now official. I checked the documentation page and they are reminiscent to the LISP ones. In one of his essays Paul Graham writes that when "you add ...
Adam Arold's user avatar
  • 1,190
8 votes
3 answers
3k views

I am new to Clojure, I am new to Macros and I have no prior background in Lisp. I went on to create my own switch case like form and ended up with this: (defmacro switch-case [v cases default] (if (...
Amogh Talpallikar's user avatar
3 votes
2 answers
6k views

I am new to C/C++. Wanted to know why we cannot declare 'extern C' for C++ macro's similar to methods/functions...which will allow macro's defined in C++ file to be accessed in .c files. Thanks in ...
Gana's user avatar
  • 411
11 votes
3 answers
1k views

I have been reading about the libraries people have written for languages like Java and C# that make use of byte code weaving to do things like intercept function calls, insert logging code, etc. I ...
mortalapeman's user avatar
  • 1,611
2 votes
2 answers
1k views

Possible Duplicate: Programming languages with a Lisp-like syntax extension mechanism I'm making a programming language, and, having spent some time in Lisp/Scheme, I feel that my language should ...
mhr's user avatar
  • 129
20 votes
19 answers
6k views

I have only a limited knowledge of Lisp (trying to learn a bit in my free time) but as far as I understand Lisp macros allow to introduce new language constructs and syntax by describing them in Lisp ...
1 vote
1 answer
490 views

I'm working for a client that has no version control system in place. I want to record changes to code without having to add all changes to a spreadsheet. I'm restricted to using Notepad++ so would a ...
br3w5's user avatar
  • 769
21 votes
1 answer
7k views

I am reading 'The Standard C Library' by PJ Plauger which is really interesting. The book explains not only how to USE the library but also how it is implemented. I have finished reading the ctype.h ...
user619818's user avatar
  • 1,813
6 votes
1 answer
395 views

On my way to learn Lisp I have discovered the all powerful and feared so called Macros, then after spending a hard time trying to understand them and their usefulness I said to myself, I FINALLY GOT ...
utxeee's user avatar
  • 161
21 votes
2 answers
2k views

I am trying to learn some LISP and I have read a lot about the importance of LISP macros so I would like to get some working experience with them. Can you suggest a practical application area that ...
Giorgio's user avatar
  • 19.8k
-4 votes
2 answers
1k views

Usually the problem of having possible multiple inclusions is solved with a series of #ifdef #ifndef but the pragmas just solves this with a single line, apparently they are really useful and can make ...
user827992's user avatar
  • 1,175
2 votes
2 answers
2k views

I am having a discussion with a colleague about using macro as a thin (extremely) layer of abstraction vs using a function wrapper. The example that I used is Macro way. #define StartOSTimer(period) ...
tehnyit's user avatar
  • 1,459
2 votes
3 answers
230 views

My editor of choice is Notepad++. It has macro capabilities, but as much as I think, I don't see how can I use it for anything. Do you use macros in your editor that have made your work easier? (...
Rodolfo's user avatar
  • 335
4 votes
1 answer
2k views

In this answer to a previous question of mine about scripting languages suitability as shells, DigitalRoss identifies the difference between the macro languages and the "parsed typed" languages in ...
Muhammad Alkarouri's user avatar
23 votes
6 answers
6k views

Common Lisp allows you to write macros that do whatever source transformation you want. Scheme gives you a hygienic pattern-matching system that lets you perform transformations as well. How useful ...
compman's user avatar
  • 1,397
31 votes
5 answers
18k views

From different comparisons among C++ templates and C#/Java generics like this one- https://stackoverflow.com/questions/31693/what-are-the-differences-between-generics-in-c-and-java-and-templates-in-c/...
Gulshan's user avatar
  • 9,542
10 votes
3 answers
2k views

The first abuse that comes to my mind in C is: #define if while But at the same time it is extremely handy and powerful when used correctly. Something similar happens with Common Lisp macros. ...
OscarRyz's user avatar
  • 1,665
45 votes
7 answers
14k views

I know that they are implemented extremely unsafely in C/C++. Can't they be implemented in a safer way? Are the disadvantages of macros really bad enough to outweigh the massive power they provide?
Casebash's user avatar
  • 7,672