On Mon, Apr 28, 2008 at 2:18 AM, Krzysztof Kowalczyk <[EMAIL PROTECTED]>
wrote:

> >  "Krzysztof Kowalczyk" <[EMAIL PROTECTED]> writes:
> >
> >  > The other form works for both msvc and gcc (see
> >  > http://codepad.org/VxF4pBHg for a proof (well, a proof that it
> >  > compiles with gcc, or at least a version of gcc)) so the #ifdef isn't
> >  > necessary, just use __VA_ARGS__ version. I verified that it compiles
> >  > with msvc 2005.
> >
> >  Using __VA_ARGS__ is not quite correct with GCC.  You should be able
> >  to call the _send (or _sendv) macro without supplying any arguments
> >  after RCV.  The comma preceding __VA_ARGS__ causes a syntax error
> >  under GCC when there are no other arguments, but if you use ##ARG it
> >  deletes the comma and all is well.
> >
> >  Does MSVC compile properly without arguments?
> >
> >  i.e. does:
> >
> >  _send("abc", 123)
> >
> >  cause a syntax error?
>
> Good point. MSVC handles that according to
> http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx
> and this test program, which compiles and works as expected with msvc
> (and doesn't compile on gcc):
>
> #include <stdio.h>
> #define np(s, ...) \
>        printf(s, __VA_ARGS__)
>
> int main(int argc, char **argv)
> {
>  int d = 4;
>  np("hello\n");
>  np("s %d", d);
>  return 0;
> }
>
> So #ifdef is needed after all. Alternatively, all places where
> _send(a,b) is used, could be changed to _send0(a,b).
>
> Here's another possible solution if we are using C99 and have inline
functions :-

#include <stdarg.h>

inline oop _send( oop msg, oop rcv, ...)
{
  va_list ap;
  register oop _r = rcv;
  struct __closure *_c;
  oop ret;

  va_start( ap, rcv);
  _c = (struct __closure *) _libid->bind( msg, _r);
  ret = (_c->method)( (oop) _c, _r, _r, ap);
  va_end( ap);
  return ret;
}
You will probably need a "#define inline __inline" for MS VC.

This is untested but should work okay. I am not at a state where I can
really test this yet, hopefully I will be able to catch up this week.

Regards,

Aaron
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to