This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C-like identity?


>>>>> "Ian" == ianb  <ianb@colorstudy.com> writes:

    Ian> A mysterious part of the C syntax I found was `...', which
    Ian> apparently can come at the end of a function definition, as
    Ian> in:

    Ian>   int foo(x, y, ...) {...}

    Ian> I've never seen this used, so I don't know what it is.  Maybe
    Ian> something like `rest'...?

Yes, it's the C equivalent of `rest'.  The functions for handling this
are va_start() (called before fetching any values), va_arg() (to fetch
successive arguments), and va_end() (to clean up).  It's easiest to
demonstrate with an example:

#include <stdarg.h>

void foo(char *fmt, ...)
{
   va_list ap;
   int d;
   char c, *p, *s;

   va_start(ap, fmt);
   while (*fmt)
      switch(*fmt++) {
         case 's':           /* string */
            s = va_arg(ap, char *);
            printf("string %s\n", s);
            break;
         case 'd':           /* int */
            d = va_arg(ap, int);
            printf("int %d\n", d);
            break;
         case 'c':           /* char */
            /* need a cast here since va_arg only
               takes fully promoted types */
            c = (char) va_arg(ap, int);
            printf("char %c\n", c);
            break;
      }
   va_end(ap);
}


For more info "man 3 stdarg", or look up the variadic function part of
the Language Features section of the GNU libc info documentation.

BTW, I'm new to the list (and to guile), and was wondering, are we
discussing ctax?  I remember seeing reference to this before, but have
looked around and can't find anything but the manual... where can I
download this?

Thanks,
Alex

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]