Boost logo

Boost Users :

From: Server Levent Yilmaz (leventyilmaz_at_[hidden])
Date: 2007-06-17 16:03:07


On 6/16/07, Tobias Schwinger <tschwinger_at_[hidden]> wrote:
>
> Server Levent Yilmaz wrote:
> > I did somehow come up with this dirty trick, though it doesn't quite cut
> it:
> >
>
> <snip code>
>
>
> >
> > any ideas?
> >
>
> Yep, here's another dirty trick ;-):
>
> #include <boost/preprocessor/detail/is_unary.hpp>
>
> #define SPECIAL (whatever)
> #define IS_SPECIAL BOOST_PP_IS_UNARY
>
> IS_SPECIAL(a) // 0
> IS_SPECIAL(b) // 0
> IS_SPECIAL(SPECIAL) // 1
>
> It isn't entirely portable to older preprocessors (that's why this code
> lives in preprocessor/detail) but should work with latest versions of
> the widely-used compilers.

That did it!! Thanks Tobias.

FWIW, I have solved my original problem too. It is in fact not an entirely
fun project, but became a helpful little library on its own, useful for
mixed language programming (C++ calling Fortran, to be specific). The idea
is the "stub code" outlined by Carsten A. Arnholm (
here<http://arnholm.org/software/cppf77/cppf77.htm#Section4>)
Arnholm generates the stub code with an external script. I managed to do it
with preprocessor only.

So, the library effectively converts the following:

FORTRAN_FUNCTION (int, foo, FOO, 3, (CHAR, double*, int&) );
FORTRAN_SUBROUTINE ( bar, BAR, 4, (CHAR, const double&, CHAR, int*) );

into,

#ifdef F77_STUB_REQUIRED

extern "C" void bar_ (const char*, const double&, const char*, int*, size_t,
size_t);
inline void BAR (
     internal_character_type v0,
     double* v1,
     internal_character_type v2,
     int& v3
     )
  {
     bar_(v0.p, v1, v2.p, v3, v0.n, v2.n);
  }

#else // in MS compilers

  extern "C" int __stdcall FOO( const char*, size_t, double*, int&);
  extern "C" void __stdcall BAR( internal_character_type, const double&,
internal_character_type, int*);

#endif

The library code is in the vault (fortran.h
here<http://boost-consulting.com/vault/index.php?direction=0&order=&directory=Preprocessor%2520Metaprogramming&>)
in case anyone is interested.

regards,
Levent

-- 
Server Levent Yilmaz
Mechanical Engineering
University of Pittsburgh


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net