Re: Preprocessing the arguments of a MACRO function ?

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

 



Hello,

Thanks a lot for your kind answer.

Maybe I can precise a bit what I am trying to do. I am using fortran 90
(not C or C++) but using cpp as a preprocessor for f90 code.

The macro I have tried is :
#define MY_ALLOCATE(MY_ARRAY(...)) allocate(MY_ARRAY(...)) \
  call foo(MY_ARRAY)


In the code, if I have for example :

integer ndim=2
MY_ALLOCATE(array1(3,-2:4,ndim)) 

/* Here I put "strange" dimensions but that, in principle could happen.
The -2:4 is to specify in f90 the indices that this array should have,
if no indices are given (no semicolon), the indices are from 1 to N
(i.e. 1 to 3 for the first dimension and 1 to ndim for the third one)*/

It should correspond to :
allocate(array1(3,-2:4,ndim))
call foo(array1)

/* In the call to foo, the "(3,-2:4,ndim)" cannot be there */

So I am trying to find a way to separate MY_ARRAY from (...) in the
Macro definition.

David

On Mon, 2011-08-29 at 17:52 +0100, Philip Herron wrote:
> On 29 August 2011 09:14, David Waroquiers <david.waroquiers@xxxxxxxxx> wrote:
> > Hello,
> >
> > I would like to make a macro MY_ALLOCATE(myarray) where myarray will
> > be something like arr(dim1,dim2,...,dimN). The MY_ALLOCATE should be
> > replaced by 2 lines :
> > 1) allocate(myarray) /* with my array being for example
> > arr(dim1,dim2,...,dimN) */
> > 2) call to another function like : foo(arr) /* where arr is myarray
> > but without the dim1 .... */
> >
> > Example :
> > ndim = 3;
> > MY_ALLOCATE(array(ndim,3,12))
> > would be changed to :
> > allocate(array(ndim,3,12))
> > call foo(array)
> >
> >
> > I have tried this :
> >
> > #define MY_ALLOCATE(myarray(myshape)) allocate(myarray(myshape)) \
> >  call foo(myarray)
> >
> > But it does not work :/
> >
> > I do not want to have something like MY_ALLOCATE(myarray,myshape), the
> > argument list needs to be exactly like in the allocate call.
> >
> > Any ideas ?
> >
> > Thanks a lot !
> >
> > David
> >
> 
> I feel a little confused with your description you want a macro to be like:
> 
> void allocate (yourtype dim1, ...)
> {
>   va_list args;
>   va_start (args, dim1)
> ...
> }
> extern void allocate (yourtype, ...);
> 
> #define my_macro(...) \
>   allocate (__VA_ARGS__)
>   do_calls (__VA_ARGS__)
> 
> my_macro (myarrary,myshape,....)
> 
> This is where i get confused you want your argument to be a call but
> then get the identifier of the call? I dont really understand.
> 
> I think thats a big enough hint for you to get started though.
> 
> --Phil



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux