Skip to main content

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
3 votes
1 answer
136 views

Testing framework with a single assertion macro

I usually use the Catch2 testing framework in my C++ projects. Unlike other frameworks, it has only one core assertion macro for all comparisons. Instead of writing ...
elehtine's user avatar
  • 133
-1 votes
1 answer
57 views

Need assistance modifying a "too large" procedure [closed]

I have a chunky VBA script that needs some help making it efficient, which I think will correct the "Procedure too Large" issue I just ran into. I run the procedure from an open workbook ...
WhiteRaven76's user avatar
4 votes
1 answer
136 views

C - Force a macro argument to be a string literal

The requirement is to define a macro which takes a single argument that is a string literal. My first try at it was to surround it with empty string literals (I got this from Modern C): ...
Harith's user avatar
  • 9,687
2 votes
1 answer
79 views

string compatible enum-like structure

So I've decided to flex showcase my "enum that accepts strings etc..." here. I don't know if it's great but I'm pretty sure it's decent. It is implemented in less than 200 lines of code (not ...
PinkTurtle's user avatar
5 votes
1 answer
236 views

C++ extended switch for any class

Was thinking about extending the C switch beyond integers. Here is what it came to - will gladly accept any suggestions for improvement. Note: "Any class" in the title is not quite correct - ...
johngo's user avatar
  • 51
3 votes
1 answer
96 views

Portable lambda emulation in C

For fun I decided to try to emulate lambda functions in plain old C. It turns out it can be easily done with a bit of macro abuse. CLambda struct stores function ...
KlemenPl's user avatar
  • 225
4 votes
1 answer
188 views

Custom derive macro to create getters and setters

To learn how custom derive macros work in Rust, I decided to create a simple derive macro to provide getters and setters for a given struct. It would be used like this: ...
Dornteufel's user avatar
5 votes
0 answers
41 views

Procedural macro to derive de/serialization trait from/to little endian bytes

I wrote a trait library that allows the de-/serialization of data structures from/to little endian bytes 1. For it I now wrote my first procedural macro 2 to be able to derive the traits ...
Richard Neumann's user avatar
8 votes
2 answers
980 views

JVM bytecode instruction struct with serializer & parser

I am writing a java class file parsing & serialization library. As part of that i needed to implement a structure for the JVM bytecode instructions as well as come up with a way to parse & ...
p0sa's user avatar
  • 81
1 vote
2 answers
340 views

Logger using variadic macros

I'm getting back into C and I wrote this variadic logger as part of a chess application I'm writing. As such I'm looking for feedback about the general approach (I'm going to give it another pass to ...
blinken_lx's user avatar
4 votes
1 answer
553 views

C23 Vector Macro Implementation

I'm trying to implement a simple type-generic Vector with macros using the newest features of C23. Looking for any advice about macro design and pitfalls because I generally avoid macros at all costs. ...
Biggs's user avatar
  • 143
3 votes
2 answers
412 views

C macro based dynamic array library

This library is a fork of eteran/c-vector. It is macro based, so that it is generic, without void pointers and additional functions. This of course means that it has the downsides of macros in C. The ...
DuckHunterZx's user avatar
5 votes
2 answers
388 views

C Macro Generic Linked List

For a recent project of mine I had to create various data structures in pure C with no external libraries (in other words, code I've written by myself), which lacks the templating and OOP capabilities ...
404 Name Not Found's user avatar
0 votes
1 answer
63 views

Code compares Columns "A" of two workbooks and copies different information to destination workbook with entire selected row. LastRow count slows code

Code explanation: I have a code, which performs two tasks - To open two workbooks, one being extract info and one destination and it compares the column A with Column A of these workbooks and all ...
Rokas's user avatar
  • 3
4 votes
2 answers
386 views

C++ (Cross-Platform) Predefined Library

As we know there is no standard way in compilers to standardize macros with compilers and different operating systems So I created this library that contains standardized compiler, os, attributes ...
Maysara Elshewehy's user avatar
4 votes
1 answer
192 views

Optimizing a large report sorting macro

I've been working on this project for my organization for a few months now, and am looking for ways to increase performance on this macro. I work for an insurance company as a claims auditor. I get a ...
Dallin DeFord's user avatar
2 votes
1 answer
192 views

Portable noreturn in C/C++ between compilers

I'm writing a C/C++ (intended to also be valid C code) for having a noreturn macro variable as widely portable as possible between C and C++ compilers. ...
Giuppox's user avatar
  • 163
2 votes
1 answer
83 views

A (Sort of) Generic Stack Implementation in C using Macros

I spent some time implementing a generic stack in C using macros. Apart from general bugs and bad practices in my code, I was wondering about the viability of an implementation like this that uses ...
vim_overlord's user avatar
7 votes
1 answer
375 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 ...
DIVIJ_404's user avatar
2 votes
4 answers
2k 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 ...
Linny's user avatar
  • 10.3k
3 votes
1 answer
63 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 ...
J. Doe's user avatar
  • 131
3 votes
0 answers
80 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 &...
Jake Grossman's user avatar
0 votes
3 answers
115 views

Populate a color table in XCB

This function has 16 repeated calls to the same function, passing in the same handles to each: ...
Ignis Incendio's user avatar
0 votes
2 answers
338 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 ...
bikash.a's user avatar
2 votes
1 answer
124 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 ...
Cédric Moers's user avatar
2 votes
1 answer
432 views

C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
xilpex's user avatar
  • 289
3 votes
0 answers
102 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 ...
J. Mini's user avatar
  • 127
3 votes
2 answers
103 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 ...
Ilian Zapryanov's user avatar
3 votes
2 answers
104 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 "...
Samiya Jabbar's user avatar
2 votes
0 answers
37 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 ...
Jon Guiton's user avatar
3 votes
0 answers
284 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 ...
Light Drake's user avatar
3 votes
0 answers
123 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 ...
Vladyslav Mozhvylo's user avatar
6 votes
2 answers
3k 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: ...
Francis Cugler's user avatar
3 votes
1 answer
140 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 ...
Chris H.'s user avatar
  • 133
3 votes
1 answer
2k 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 ...
sudo rm -rf slash's user avatar
4 votes
2 answers
112 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 ...
remyfra's user avatar
  • 41
1 vote
0 answers
130 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....
Satish's user avatar
  • 11
7 votes
3 answers
8k 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 ...
Alex Angel's user avatar
3 votes
0 answers
247 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 ...
CircArgs's user avatar
  • 131
3 votes
1 answer
141 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 ...
OneArb's user avatar
  • 211
7 votes
4 answers
1k views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
alx - recommends codidact's user avatar
3 votes
0 answers
127 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 ...
Andrew Kravchuk's user avatar
2 votes
1 answer
2k 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 ...
LeoVen's user avatar
  • 335
4 votes
2 answers
2k 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 ...
user673679's user avatar
  • 11.8k
3 votes
0 answers
176 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: ...
LeoVen's user avatar
  • 335
8 votes
5 answers
5k 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 ...
klutt's user avatar
  • 903
3 votes
2 answers
182 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 ...
Norbert Skalski's user avatar
2 votes
2 answers
236 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 ...
Nahuatl's user avatar
  • 131
8 votes
3 answers
3k 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: ...
Indiana Kernick's user avatar
6 votes
2 answers
8k 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) ...
L_J's user avatar
  • 263