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

0 votes
0 answers
54 views

Lisp Macro that can take Forth like order

I am studdying Lisp after many years of C like languages (C, C++, C#, Java, Javascript, Go, Haxe). I've written already some usefull programs with Lisp, and I feel already productive enough with it, I'...
Sam Washington's user avatar
4 votes
4 answers
1k views

Is updating a macro value in the Xcode preprocessor's macros violating the open–closed principle?

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

Using a preprocessor macro to wrap functions?

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
630 views

Current industry standard with regards to C macros [closed]

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
134 views

Detecting keyboard "callbacks" directly from a keyboard not from a operating system

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

Is using C/C++ macros as a shortcut for conditional compilation a good practice?

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

Is this using macros to define classes that fit a pattern in C++ a sound idea?

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,320
1 vote
1 answer
6k views

Using a macro for a libraries namespace?

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,320
3 votes
1 answer
6k views

Declaring functions using macros?

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
141 views

Time profiling - is using macros bad?

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
3k views

How can a compiler be written for a language that allows rewriting code at runtime (such as Lisp macros)?

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,887
2 votes
3 answers
322 views

Writing a #define for a common statement

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
861 views

when writing platform specific code, is using separate .cpp always preferred instead of using #ifdef?

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,863
2 votes
1 answer
3k views

Does having so many macros (#define) increase compilation time due to prolonged pre-processing?

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
341 views

How to stay DRY with return values

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

15 30 50 per page