2022 Developer Survey is open! Take survey.

Questions tagged [macros]

A macro in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to a replacement output sequence (also often a sequence of characters) according to a defined procedure. Do not use this tag for questions regarding Microsoft's Visual Basic for Applications. VBA evolved from an early macro language, but is not a macro language itself.

Filter by
Sorted by
Tagged with
7 votes
1 answer
281 views

Pseudo-Generic Array Stack in C

I have implemented an array based pseudo-generic stack in C using macros. The code works fine for all data types. Is it a good idea to implement such a data structure using macros? array_stack.h ...
user avatar
2 votes
3 answers
299 views

Simplified print and input macros in C

For a program I'm writing, it requires a lot of printing and receiving user input. I've found it cumbersome to keep specifying the type strings in printf, and ...
user avatar
  • 9,466
2 votes
0 answers
39 views

Fast git change sets with git wrapping scripts

After having a good experience with virtualenvwrapper built on top of the venv, I thought maybe it could be benefitial to have similar shortcuts for standard activities with git which could be time ...
user avatar
  • 121
2 votes
0 answers
50 views

Implement easy CLI options in C using a single-file header

I'm a computer science student, and in 2 of my courses this semester we are writing short C programs to demonstrate the things we are learning about. All of these programs require command-line flags &...
user avatar
-1 votes
3 answers
83 views

Populate a color table in XCB

This function has 16 repeated calls to the same function, passing in the same handles to each: ...
user avatar
0 votes
0 answers
45 views

Creating Pivot Table taking time at average vales

I have created a VBA macro to create a pivot table automatically. But taking 15 to 20 minutes of time to complete the macro. Especially at the point of below code taking half of the time. Review Code ...
user avatar
0 votes
2 answers
77 views

Improving Speed of VBA Code - Copy/paste two sets of variable, Excel does a calculation, returns a value then copy/paste the output value

I am attaching the code here. I am very new to VBA and trying to do a complex calculation using Macro. Please help me improve the speed of the attached code. The code works fine and produces the end ...
user avatar
2 votes
1 answer
84 views

Is this a good design for runtime Macro execution?

I am developing a system for runtime macro executions in an automatic test environment. Macros are defined in an xml and are for configuring multiple devices/DUTs for a specific use case. The xml ...
user avatar
2 votes
1 answer
191 views

C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
user avatar
  • 269
3 votes
0 answers
89 views

Was this an idiomatic and prudent way to extend R's matrix multiplication syntax? Should I have used R's object system?

After reading one too many Lisp books, I decided to try extending R's syntax. My goal was to implement repeated matrix multiplication in a way such that I could write ...
user avatar
  • 61
3 votes
2 answers
68 views

std::accumulate alternative for the C programming language

I've come up with some simple implementation for algorithms in C and more specifically for std::accumulate alternate since I ...
user avatar
3 votes
2 answers
64 views

internal links b/w sheets of merged workbooks, using VBA (EXCEL MACROS)

My aim is to merge all workbooks having multiple sheets from any specified folder to one workbook of multiple sheets. The problem is I don’t want external links to be maintained, If I use "...
user avatar
2 votes
0 answers
35 views

Is this use of macros to trace program flow portable and free of major pitfalls? [closed]

The program below defines macros START and END that expand to the left and right curly bracket symbols plus some example tracing code. Is this a portable use of a macro and are there any obvious major ...
user avatar
3 votes
0 answers
155 views

Rust Builder pattern derive-macro

Inspired by dtolnay's procedural macro workshop (on Github), I have implemented a derive-macro to automatically implement the Builder pattern on a Rust struct, which allows a struct instance to be ...
user avatar
1 vote
0 answers
65 views

Trying to speed up VBA macro to generate viable Daily Fantasy Sports lineups

I have created the code below to generate daily fantasy sports lineups from a pool of players that have been entered in my excel file. Right now the code can run through about 16,500 combinations per ...
user avatar
3 votes
0 answers
50 views

Yet another reflection library

Tried to do my own implementation of reflection(introspection) for using in my next projects. Is it optimized at compile time? If no, how can I improve it? This macro is good interface for adapting ...
user avatar
5 votes
2 answers
2k views

A simple error messaging and logging system via macro(s) in C++

I'm just trying to build a quick and crude error messaging system. It currently looks like this: ...
user avatar
3 votes
1 answer
131 views

COVID model using UVA data

I have built a COVID model using UVA data. Currently that data is unavailable so I'm using another source. The new source is, of course, a different format. So rather than refactor all of my model ...
user avatar
2 votes
1 answer
620 views

C++17 enum macro with to_string operator

I created a simple enum macro that creates a to_string method for the enum. This has been done before, but my version is designed to compile quickly. From what I ...
user avatar
4 votes
2 answers
94 views

Time axis with working days, weeks numbers, month-year

I made the bellow macro to create a time line in excel. It shows the working days, the week numbers and the month together with the year. First I start with projectstart date and projectend date. As ...
user avatar
  • 41
1 vote
0 answers
120 views

Optimizing VBA code , Takes more than 50 minutes to update

Could you please help me optimize the macro, Its taking more than 50 minutes but still no success. The For loop is looping untill 1.0 million + rows. Screen is flickering. I have tried Application....
user avatar
  • 11
1 vote
1 answer
3k views

Macro to generate an enum and an array of strings

Often when I find myself working with magic number enum values and I want to know what they represent, so I create an array of strings in order to print out their label. This macro automates that ...
user avatar
3 votes
0 answers
172 views

Rust List comprehension macro

I'm very new to Rust and as I've been going through the book I became very interested in its macros. To better understand them I tried to write something of a usable list comprehension like those in ...
user avatar
  • 131
3 votes
1 answer
103 views

Clang preprocessor concatenates an extra space vs. gcc - standard C99

I maintain a C library project both on gcc and clang. I am looking for advice on how to make the following macros more portable, terse, readable or standard abiding. When I compile ...
user avatar
  • 211
5 votes
3 answers
576 views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
user avatar
  • 1,858
3 votes
0 answers
111 views

Racket macro for variadic FFI

I'm working on FFI wrapper for SDL2 library in Racket. The library includes several variadic functions (e.g. SDL_SetError, SDL_LogMessage etc); Racket FFI does not have straight way for importing ...
user avatar
2 votes
1 answer
1k views

Generic Macro Generated Linked List in C

Generate a linked list of any type using macros. The linked list contains functions for adding and removing elements to both ends and also at the middle. You can also add elements relatively to a list ...
user avatar
  • 347
4 votes
2 answers
934 views

Macros for bitsets / bit-flags in C

Context: I have some C code that uses a lot of bit-flags. The flag-sets may have a couple of hundred members. Currently these flags are defined as a 32-bit mask that must be applied to a specific ...
user avatar
3 votes
0 answers
124 views

Simple generic macro-generated containers

In order to learn macros in C I decided to make a generic data structures generator for other projects that I have in C. The main macros are the following: ...
user avatar
  • 347
8 votes
5 answers
3k views

Macro for allocation in C

As we all know, the syntax of allocating memory is a bit clunky in C. The recommended way is: int *p; int n=10; p = malloc(n*sizeof *p); You can use ...
user avatar
  • 903
3 votes
2 answers
160 views

Replace a #define/template "Variable Wrapper" system with a pure template/OOP solution

I have an inherited code base that I am looking to improve. Below is a "variable wrapper" template class and #defines that i would like to replace with a template only solution, or redesign ...
user avatar
2 votes
2 answers
200 views

Index Match implementation

The code below takes header variables, retrieves the column index, and then, using an Index/Match function, returns data from a matching account number. The reason it is written this way is because I ...
user avatar
8 votes
3 answers
2k views

The perfect function alias

For many years, I have waited for function aliases in C++. They still aren't here. I've been using macros to generate wrapper functions. This is my best attempt at the perfect function alias: ...
user avatar
1 vote
0 answers
140 views

Clojure macro to gather functions in a namespace into a map

I'm learning Clojure via a pet project. The project would consist of several workers that would be called from other functions. Each worker is defined in their own namespace as a set of functions (...
user avatar
6 votes
2 answers
7k views

Calendar for any given month/year

This is one of my first C++ training project where I created the console application which displays the calendar of any given month. I observed how offset of days (empty places on the calendar) ...
user avatar
  • 263
0 votes
1 answer
84 views

All of Clojure's Expression Threading Macros

I was bored and in a mood to write some macros, so I decided as an exercise to try and remake each of the standard threading macros: ->, ...
user avatar
5 votes
2 answers
2k views

Format log with a small macro logger

The goal of this code is to format any log to STDOUT and STDERR with the file and the line of where the call is made. I took ...
user avatar
  • 243
3 votes
1 answer
56 views

Function declarations using macros to support multiple platforms

I wrote a C++ plugin that retrieves screen pixel. It works on Windows and Android. I noticed that dllexport is only required on Windows but not on Android and ...
user avatar
15 votes
1 answer
825 views

Signed integer-to-ascii x86_64 assembler macro

I have implemented an algorithm which converts a signed integer to its ASCII equivalent string with the corresponding sign as a first byte. I have tested it on several numbers and it worked correctly. ...
user avatar
  • 771
-1 votes
1 answer
287 views

Increase the execution speed of VBA macro code

I am providing you with the code of my macro and hope that somebody can tell me what is making my macro slow and provide me with a solution as to how to make it run faster. Currently the execution of ...
user avatar
  • 1
5 votes
3 answers
2k views

Fastest FIFO with macros for use embedded devices

UPDATE (a year later) Since this post the code has turned into a small library called fifofast and is hosted on github under the MIT License. This note is meant for anyone who stumbled across this ...
user avatar
  • 161
2 votes
1 answer
485 views

Objective C implementation of Swift's if-let

This [Objective-]C-preprocessor macro currently handles single-variable if-let-not-nil and if-let-is-type, but doesn't handle multiple simultaneous tests and doesn't handle ...
user avatar
  • 121
1 vote
1 answer
54 views

Macro that generates a defn

I need to save nested data to disk for a project. Right now, my state is a nested record, and has proven to be a pain to serialize. I tried compressing it to a map, but after testing it, I realized my ...
user avatar
3 votes
1 answer
3k views

Speed up Excel Macro b/n copy and paste external files

I posted on the Stack Overflow. They recommended me to post on here So the whole scope of this Excel file is to copy and paste from other 27 external files to the current Excel file one by one. to ...
user avatar
3 votes
0 answers
113 views

Allowing switching between operator[] and at() based on NDEBUG macro version

The problem: std::vector and other containers have two functions for accessing / modifying their content: operator[] and ...
user avatar
  • 571
6 votes
1 answer
227 views

Using get-setf-expansion

In a previous post at Simplifying complex setf expressions, @sds suggested using the get-setf-expansion macro for implementing place modification, as discussed in ...
user avatar
  • 405
12 votes
3 answers
17k views

Endianness conversion in C

I have written a simple C header for converting the endianness of short integers and long integers. It uses the GCC macro ...
user avatar
  • 1,631
-2 votes
2 answers
997 views

Using C preprocessor macro instead of private static const [closed]

Recently I have been using more macros in my C++ code. I wrote a class with a private static const float because it is useful to prevent making mistakes. Then I ...
user avatar
  • 157
3 votes
1 answer
296 views

Simplifying Macro-Generating Racket Macro

I'm trying to write a small macro library in Racket that extends a few of the racket/match functions I use, by printing which clause was expanded. While this seems ...
user avatar
2 votes
1 answer
61 views

Custom threading macro

To help myself learn macros, I made a custom version of the threading macro that lets you choose which argument the "thread" gets put into. My main concern is simplifying it, and making it more ...
user avatar