Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

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
4 votes
1 answer
94 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): ...
3 votes
1 answer
92 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 ...
3 votes
1 answer
138 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 ...
2 votes
1 answer
76 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 ...
5 votes
1 answer
234 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 - ...
4 votes
1 answer
174 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: ...
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 ...
5 votes
0 answers
35 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 ...
8 votes
2 answers
976 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 & ...
1 vote
2 answers
321 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 ...
4 votes
1 answer
520 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. ...
3 votes
2 answers
382 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 ...
5 votes
2 answers
373 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 ...
0 votes
1 answer
62 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 ...
4 votes
2 answers
380 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 ...
4 votes
1 answer
191 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 ...
3 votes
1 answer
61 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 ...
2 votes
1 answer
181 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. ...
2 votes
1 answer
82 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 ...
7 votes
1 answer
373 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 ...
2 votes
3 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 ...
3 votes
0 answers
72 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 &...
-1 votes
3 answers
112 views

Populate a color table in XCB

This function has 16 repeated calls to the same function, passing in the same handles to each: ...
0 votes
2 answers
330 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 ...
2 votes
1 answer
122 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 ...
2 votes
1 answer
425 views

C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
12 votes
3 answers
27k 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 ...
6 votes
2 answers
2k views

Generic vector implementation in C using macros

I while ago I experimented with macros in C and came up with the idea of implementing a generic vector library using macros. This code uses the non standard typeof ...
3 votes
0 answers
99 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 ...
3 votes
2 answers
99 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 ...
3 votes
2 answers
103 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 "...
3 votes
1 answer
138 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 ...
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 ...
3 votes
0 answers
281 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 ...
3 votes
0 answers
120 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 ...
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: ...
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 ...
4 votes
2 answers
109 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 ...
1 vote
0 answers
128 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....
15 votes
1 answer
1k 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. ...
24 votes
3 answers
1k views

Formatted print without the need to specify type matching specifiers using _Generic

This code allows printing in C with a style similar to C++ ostream. By using _Generic() (see ...
3 votes
0 answers
245 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 ...
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 ...
5 votes
3 answers
1k views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
3 votes
0 answers
126 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 ...
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 ...
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 ...
3 votes
0 answers
175 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: ...
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 ...
3 votes
2 answers
179 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 ...