Skip to main content

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

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
704 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
145 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
906 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

15 30 50 per page