Re: idc for windows platform
On Mon, Apr 28, 2008 at 2:28 AM, Aaron Gray <
aaronngray.lists-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
On Mon, Apr 28, 2008 at 2:18 AM, Krzysztof Kowalczyk <
kkowalczyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> "Krzysztof Kowalczyk" <
kkowalczyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.
A hacked PoC :-
Aaron
<div>
<div class="gmail_quote">On Mon, Apr 28, 2008 at 2:28 AM, Aaron Gray <<a href="mailto:aaronngray.lists@...">aaronngray.lists@...</a>> wrote:<br><blockquote class="gmail_quote">
<div class="gmail_quote">
<div>
<div></div>
<div class="Wj3C7c">On Mon, Apr 28, 2008 at 2:18 AM, Krzysztof Kowalczyk <<a href="mailto:kkowalczyk@..." target="_blank">kkowalczyk@...</a>> wrote:<br><blockquote class="gmail_quote">
<div>> "Krzysztof Kowalczyk" <<a href="mailto:kkowalczyk@..." target="_blank">kkowalczyk@...</a>> writes:<br>><br>> > The other form works for both msvc and gcc (see<br>> > <a href="http://codepad.org/VxF4pBHg" target="_blank">http://codepad.org/VxF4pBHg</a> for a proof (well, a proof that it<br>
> > compiles with gcc, or at least a version of gcc)) so the #ifdef isn't<br>> > necessary, just use __VA_ARGS__ version. I verified that it compiles<br>> > with msvc 2005.<br>><br>> Using __VA_ARGS__ is not quite correct with GCC. You should be able<br>
> to call the _send (or _sendv) macro without supplying any arguments<br>> after RCV. The comma preceding __VA_ARGS__ causes a syntax error<br>> under GCC when there are no other arguments, but if you use ##ARG it<br>
> deletes the comma and all is well.<br>><br>> Does MSVC compile properly without arguments?<br>><br>> i.e. does:<br>><br>> _send("abc", 123)<br>><br>> cause a syntax error?<br><br>
</div>Good point. MSVC handles that according to<br><a href="http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx</a><br>and this test program, which compiles and works as expected with msvc<br>
(and doesn't compile on gcc):<br><br>#include <stdio.h><br>#define np(s, ...) \<br> printf(s, __VA_ARGS__)<br><br>int main(int argc, char **argv)<br>{<br> int d = 4;<br> np("hello\n");<br> np("s %d", d);<br>
return 0;<br>}<br><br>So #ifdef is needed after all. Alternatively, all places where<br>_send(a,b) is used, could be changed to _send0(a,b).<br><br>
</blockquote>
</div>
</div>
<div>Here's another possible solution if we are using C99 and have inline functions :-</div>
<div> </div>
<div>#include <stdarg.h></div>
<div> </div>
<div>inline oop _send( oop msg, oop rcv, ...)<br>{<br> va_list ap;<br> register oop _r = rcv;<br> struct __closure *_c;<br> oop ret;</div>
<div>
<br> va_start( ap, rcv);<br>
</div>
<div> _c = (struct __closure *) _libid->bind( msg, _r);<br> ret = (_c->method)( (oop) _c, _r, _r, ap);<br>
</div>
<div> va_end( ap);<br>
</div>
<div> return ret;<br>}<br>
</div>
<div>You will probably need a "#define inline __inline" for MS VC.</div>
<div> </div>
<div>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.</div>
<div></div> </div>
</blockquote>
</div>
<div>A hacked PoC :-</div>
<div> </div>
<div> <a href="http://codepad.org/8tZyQphW">http://codepad.org/8tZyQphW</a>
</div>
<div> </div>
<div>Aaron</div>
<div> </div>
<blockquote class="gmail_quote">
<div class="gmail_quote">
<div>
<span></span> </div>
<blockquote class="gmail_quote">
<div class="gmail_quote">
<div> </div>
</div>
</blockquote>
</div>
</blockquote>
</div>