#78 fix -cvs crash due to bad va_arg usage

Dan Nelson

Ever since the coroutine code got checked in, -cvs joe (compiled using gcc) would segfault as soon as I pressed a key in the edit window. A little testing discovered that all non-gcc compilers had issues with cmd.c.

Sun Studio cc:

"cmd.c", line 369: syntax error before or at: *

Intel icc:

cmd.c(369): error: expected a ")"
func = va_arg(args, int (*)(void *obj, int));

Tru64 cc:

cc: Error: cmd.c, line 369: Missing ")". (closeparen)
func = va_arg(args, int (*)(void *obj, int));

A quick google search on "va_arg pointer to function" got me to the C FAQ ( http://www.c-faq.com/varargs/funcptr.html ) that says the varargs macro can't be used directly on pointer-to-function types, which makes sense because va_arg needs to generate a pointer-to-pointer-to-function type, which would look like "int (**)(void *obj, int)", and there's no way the va_arg macro could know to insert the extra * in the middle of the expression. gcc shouldn't have even allowed (int (*)(void *obj, int)*) to be parsed...

Converting the offending code to use a typedef fixed the compilation problems on non-gcc compilers, and fixed the crash on gcc systems.


  • Dan Nelson

    Dan Nelson - 2007-02-14

    va_arg fix

  • Joe Allen

    Joe Allen - 2007-03-16

    Logged In: YES
    Originator: NO

    Thanks, for this. I have tested the coroutine library on a wide variety of hardware, but not much since integrating it with the rest of JOE.

    I'm actually right in the middle of a major tedious refactoring for this coroutine stuff, so cvs is not in a good state (but the last release is tagged). One issue I'm running into is how to best integrate it with JOE's macro system. It's turning out to be not as straightforward as I thought it was going to be.

  • Joe Allen

    Joe Allen - 2008-10-23
    • status: open --> closed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks