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 ...
1
vote
1answer
33 views
8
votes
3answers
940 views
Would this macro to call printf() be considered bad coding style in the corporate world?
I wrote this program:
...
4
votes
3answers
160 views
Penney Game - mapping macros to strings
The SPOJ problem:
Given a 40 character string representing outcomes of 40 coin tosses,
find the frequency destribution of all the possible outcome triplets.
So, for string like : HHHH....40 Hs ...
10
votes
2answers
223 views
Template vector struct in C11
This one review will be a little bit tricky: I was trying to implement a template Vector struct in C11. Of course, templates don't really exist in C11, so I used a ...
1
vote
1answer
234 views
8
votes
2answers
130 views
Macro that interchanges 2 arguments
Define a macro swap(t, x, y) that interchanges two arguments of type t.(Block structure will help.)
The ideea is that a ...
6
votes
1answer
914 views
Variadic macro enum class “reflection” in C++11
I recently had the need of "reflecting" multiple enum class constructs in order to get their elements' names as std::string ...
4
votes
2answers
85 views
Macros to detect UTF-8
I'm working on a program that handles UTF-8 characters. I've made the following macros to detect UTF-8. I've tested them with a few thousand words and they seem to work.
I'll add another one to do ...
4
votes
1answer
118 views
AppleScript to close running processes
I've been trying to emulate MS Windows behavior on my OS X and close processes that do not have a window.
What I'd really like to do is "quit" the process on clicking the red "x" button. Instead, ...
1
vote
0answers
52 views
`multiple-value-call` in Scheme
Common Lisp has a "special operator" called multiple-value-call, which does something similar to Scheme's call-with-values but ...
1
vote
0answers
53 views
Latex, named parameter macros [closed]
Using what I learnt from the TeX.SE question
I came up with this:
...
5
votes
1answer
124 views
C++: Generating similar methods with macros
I am currently working on a project that involves Lua. For convenience, I created a wrapper class for the Lua state structure. However, I also added some methods for getting globals and table fields. ...
2
votes
2answers
283 views
C try/catch macros
I've created simple try/catch macros that now I'd like to promote to wider use in my projects.
I would have really liked to be able to do without global variables but I have not found any way to do ...
4
votes
2answers
318 views
A defined macro to copy selected values of std::vector to an array using std::copy
Thought I share this piece of code to the world. But be aware, I am not sure if this piece of code is safe and efficient. Feel free to improve it or give some feedback and suggestions.
...
2
votes
1answer
218 views
Simplify complex hash-table manipulations in Common Lisp
I'm trying to write a simple triplestore in Common Lisp that will store triples in the form subject-predicate-object. The code is inspired by the book "Programming the Semantic Web".
...
4
votes
2answers
202 views
Is this C game code OK? Structures and bitfield flags with some macros to handle them
I wrote some C code for working with some data for a game, I wanted to know what do you think and what could I do to improve it, what should I change, etc.
These are just some lines of the file, you ...
4
votes
1answer
932 views
Qt foreach-like alternative to iterate over value AND key of an associative container
The Qt documentation recommend an iterator-based solution to iterate over an associative container like QMap and QHash, and I always wondered if there really isn't a (nice) solution using a foreach ...
1
vote
2answers
128 views
2
votes
2answers
1k views
Objective-C debug macros
I'm looking for a review of my macros. I have these in the project pre-compile header. I tent to copy them into all my new projects as well, unless its a very simple project.
...
6
votes
2answers
486 views
Solving the problem of using directives in a header file with a macro. Is this stupid?
I am writing some library code that is mostly templates and so is all contained in header files. I know that placing a using declaration in a header will pollute all the files that include it, but I'm ...
10
votes
6answers
1k views
3
votes
2answers
98 views
Keys in mode maps
I noticed a pattern in some elisp modes I was putting together:
(let ((map (make-sparse-keymap)))
(define-key map KEY 'FN)
...
(setq FOO map))
so I wrote ...
7
votes
4answers
2k views
'do { statement; } while(0)' against 'statement' when writing C macro? [closed]
Which one of the following is preferrable and why when writing C macro?
Type 1
#define I2C_START() I2C_WAIT_IDLE(); SSP1CON2bits.SEN = 1
Type 2
...
3
votes
1answer
165 views
Is this a good way to implement let-with?
I've implemented a let-with macro that takes an association list, keyed by symbols, that enables code to bind their corresponding values to local variables.
It's ...