help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Macro definitions


From: Francesco Abbate
Subject: Re: [Help-gsl] Macro definitions
Date: Sat, 27 Aug 2011 11:25:40 +0200

2011/8/27 Greg Lyukshin <address@hidden>:
> Hello everyone,
> Forgive me for a silly question but I can't seem to be able to find the
> meaning of macro called MULTIPLICITY. It is used all over, including  the
> source file called permute_source.c, which is located in the permutation
> folder of gsl libraries.
> Does anyone know what MULTIPLICITY means?
> Thank you!

Hi Greg,

the MULTIPLICITY macro definition is part of the GSL template system.
You will find the definition in the file templates_on.h in the root
directory.

The meaning of the MULTIPLICITY is to take into account complex number
that can be expressed as a pair of real number. So MULTIPLICITY is 2
for complex number and 1 for real number independently of the base
type that can be either float, double or also other more exotic types.

To get an idea of how the template system works you can look at
permute.c and permute_source.c for example. In the first one you will
see something like:

#define BASE_GSL_COMPLEX
#include "templates_on.h"
#include "permute_source.c"
#include "templates_off.h"
#undef  BASE_GSL_COMPLEX

[...]

#define BASE_DOUBLE
#include "templates_on.h"
#include "permute_source.c"
#include "templates_off.h"
#undef  BASE_DOUBLE

and in permute_source.c you will have the real code but parametrized
on some macro definitions like MULTIPLICITY and some macro functions
like TYPE, FUNCTION, etc.

This mechanisms allows to have a single source (permute_source.c) that
is specialized for different base types. It does actually achieve what
is usually done in C++ with templates by using the C pre processor.

This kind of technique can be useful for any C applications that need
some template specialization of the code when C++ cannot be used.

I hope that helps.

Best regards,
-- 
Francesco



reply via email to

[Prev in Thread] Current Thread [Next in Thread]