Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.[Tag:vba] evolved from an early macro language, but is not a macro language.

1
vote
1answer
26 views

Bash function , extract word from string and code adjustment

I use ImageMagick to crop image, encapsulate the related code to functions. Here is the code: ...
-1
votes
0answers
13 views

Mac Bash: how to combine changing directory with pwd to one line code? [on hold]

Use the following code to change directory to the super folder ,and print the working directory. cdUp(){ cd "$(dirname "$1")/.." pwd; } like drag a file to ...
2
votes
0answers
29 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: ...
3
votes
4answers
801 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 ...
3
votes
2answers
132 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 ...
2
votes
2answers
114 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 ...
7
votes
3answers
277 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: ...
1
vote
0answers
35 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 (...
6
votes
2answers
1k 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) ...
0
votes
1answer
49 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: ->, ...
5
votes
2answers
500 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 ...
3
votes
1answer
43 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 ...
10
votes
0answers
123 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. ...
-1
votes
1answer
163 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 ...
5
votes
3answers
752 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 ...
2
votes
1answer
181 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 ...
1
vote
1answer
42 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 ...
3
votes
1answer
2k 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 ...
3
votes
0answers
67 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 ...
6
votes
1answer
122 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 ...
12
votes
3answers
6k 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 ...
-2
votes
2answers
239 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 ...
3
votes
1answer
151 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 ...
3
votes
1answer
48 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 ...
3
votes
2answers
346 views

scope_exit macro

This is actually not something new, but I think many people wanted something useful and not incredibly complicated. So, here it is: ...
4
votes
1answer
2k views

Check for iOS version

Here's an approach i came up with for checking IOS versions. ...
1
vote
0answers
226 views

Interpreter for an assembly language with variadic instructions

I am currently implementing a virtual machine that runs a programming language similar to assembly. The difference is that an instruction in this language can have any number of operands. and the ...
1
vote
0answers
49 views

Implementation of catch test framework in Racket

As an exercise in learning how to use Racket macros I decided to implement a subset of the features in the catch test framework for C++. In particular the catch test framework has a unique feature ...
1
vote
4answers
2k views

Macro for rounding with variable precision

I use the following MY_ROUND macro for rounding: ...
3
votes
1answer
59 views

Saving the values of all variabled declared in a block

Often when running exprimental code to empirically investigate an algorithm, you tweak a parameter, then rerun the code, and generate a bunch of saved models for various parameters. To make sure I ...
14
votes
3answers
2k views

On-the-fly destructors

Due to my needing to use C libraries inside C++, I kept finding myself wanting to be able to ensure that the free function got called, even if an exception got ...
5
votes
3answers
77 views

Four versions of a database-creation function with different error handling

I'm starting a new, small C project and would like to have the safest, cleanest and shortest error handling code possible. Here is a comparison of different ways to handle errors in the same C ...
4
votes
2answers
60 views

Error-checking macro to jump to specified label given a failing statement

I'm starting a new C projet and I want to have the cleanest and shortest error checking code possible. To that aim, I often use two things : functions return 0, ...
3
votes
1answer
135 views

Once-only macro

I have been learning common lisp and am a newbie, using the great book Practical Common Lisp. There is a once-only macro in the book that I spent a lot of time figuring out how it works. Even after I ...
2
votes
2answers
87 views

A stack optimized for filter queries, written in the C++ preprocessor

Given a stack with N elements and a query Q, we need to find all elements of stack for which ...
4
votes
1answer
76 views

Introduce bindings for macro user

I'm doing the Racket track on exercism.io and solved the grains exercise: Write a program that calculates the number of grains of wheat on a chessboard given that the number on each square doubles. ...
2
votes
1answer
400 views

Mutable stack in Racket

I'm learning Racket and have implemented a mutable stack, which is just a bunch of wrappers around an underlying struct containing a size and buffer list (so it's ...
9
votes
6answers
1k views

Length of a C string, capped to some maximum

If I have a oneliner in C such as size_t maxSizeOf(const char *s) { return strlen(s) > M_MAX_SIZE ? M_MAX_SIZE : strlen(s); } would it be better to have ...
4
votes
2answers
243 views

C program to generate Seed programs from statically defined Befunge code

My program takes static input, and then number crunches for a few hours. I am currently using Macros, but is there a better, more "user friendly" way to do this without losing on performance. I have ...
15
votes
2answers
375 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
1answer
93 views

Scale-able API development with macro definitions

In a couple of months I'll be part of a large(ish) project, and there's good chances my team will be a lot bigger, with at least 2 programmers (probably 3) and some 3-5, or more, consumers of the API ...
3
votes
1answer
91 views

in-nest-sequence: sequence generator in Racket

in-nest-sequence is a sequence generator that takes a function and an initial value, and the return value of invoking the function on the current value is used as ...
8
votes
1answer
697 views

Const by default

Being a C++ developer, but also having been influenced by functional languages, I strongly believe that const should be the default for the vast majority of all ...
2
votes
2answers
120 views

C++ Minimalistic Unit Testing Library

I was looking for a unit testing library for C++, and I found many. Unfortunately, I decided I didn't want to use any of them. I decided to make my own. This is the result. I made heavy use of the ...
7
votes
1answer
213 views

Unit test macro

I have written a couple of macros (? and ??) for performing unit tests, but I'm having some difficulty with modifying it, so I ...
4
votes
1answer
632 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 ...
19
votes
1answer
343 views

Suggesting “safe enum” class for ISO C

There are quite some questions and answers about how to make enum really type-safe and I didn't find a solution that ensures both type safety and valid values. So I ...
1
vote
0answers
57 views

Creating class method using macro to accept Visitator for each of their fields

I had a lot of classes that used a macro with listed fields. The macro was used to serialization, more like MSGPACK_DEFINE. I need a substitution of this mechanism, ...
7
votes
1answer
174 views

Validation macro

I would like a review of a Scala validation library I am writing. For now we can focus on the regular expression component. The usage is described in RegexExample.scala There is an outline of the ...
7
votes
4answers
360 views

Macro enabling Python style 'with' in C++

I am developing a simple macro that enables Python style 'with' in C++. I have shamelessly prefixed the macro name with BOOST_ - primarily because there's a ...