Duplicating source code

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

camsr wrote:Another example of something I would like to do on the source code level is write an iteration to create a dataset. Instead of it actually compiling an iteration, the parser would see it as a source code level event and expand it in a way that makes sense... anything like this possible?
Not sure if I understood what you mean.
You are not looking for https://en.wikipedia.org/wiki/Loop_unrolling , are you?

Post

PurpleSunray wrote:
camsr wrote:Another example of something I would like to do on the source code level is write an iteration to create a dataset. Instead of it actually compiling an iteration, the parser would see it as a source code level event and expand it in a way that makes sense... anything like this possible?
Not sure if I understood what you mean.
You are not looking for https://en.wikipedia.org/wiki/Loop_unrolling , are you?
Yes, except it unrolls the loop during pre-processing, not compilation.

Post

Hm, don't know about any special macro-trick (maybe others?^^), other than simply writing down the combinations.

Something like:

Code: Select all

#define DO_IT_1(f) f
#define DO_IT_2(f) f f
#define DO_IT_3(f) f f f

#define DO_IT(n,f) DO_IT##n(f)

void foo()
{
    DO_IT(3, do_work(););
}

Post

Not quite on your C++ or whatever source code but you could do it with m4 or similar.

https://www.gnu.org/software/m4/manual/m4.html#Forloop

I worked on something many moons ago where we used Ada95 with an embedded Python interpreter for generating data. Not for everybody though...

Post

...

Post

PurpleSunray wrote:
Something like:

Code: Select all

#define DO_IT_1(f) f
#define DO_IT_2(f) f f
#define DO_IT_3(f) f f f

#define DO_IT(n,f) DO_IT##n(f)

void foo()
{
    DO_IT(3, do_work(););
}
That's a good example. But to define do_it_n like that is archaic IMO.

Post

Just out if intereset, what's the modern way of doing that?
(I rarely use such macros / pre-processor at all. I trust the C compiler on doing inline, loop unrolling & co - and if I don't trust, I trust nasm, but that code is for a specific cpu & featureset then).

Post

what's the modern way of doing that?
Template specialization based on integer parameter?
~stratum~

Post

Well, my C compiler dosn't like templates (but for .cpp it works ofc :P )

Post

I might be slightly late to this and it might be irrelevant (sorry if it is something you already know). I've found clang is really good at making inline decisions and msvc is pretty useless (probably because ms recommend profile guided optimisation for getting the best results from msvc). Clang for windows is great because the C++ libs it produces have binary compatibility with msvc (mostly ;-)) so I tend to separate out things I want compiled in clang/msvc using separate library projects.

You can also write your own extensions for clang which might be a good way to do something imaginative if you can't find another way to do it using macros/meta programming.

Post

I switched to clang because of all the tools (just to mention some more reasons to change to clang :D )
gcc+valgrind can't keep up with AddressSanitizer/ThreadSanitizer and mvsc has nothing that even comes close it.

Post Reply

Return to “DSP and Plugin Development”