user504909
user504909

Reputation: 9549

in #define directive, how to fix the "expected declaration specifiers before"?

I have source code contains cccp.c file. on line 195 there is:

#if defined (__STDC__) && defined (HAVE_VPRINTF)
# include <stdarg.h>
# define VA_START(va_list, var) va_start (va_list, var)
# define PRINTF_ALIST(msg) char *msg, ...
# define PRINTF_DCL(msg)
# define PRINTF_PROTO(ARGS, m, n) \
            PROTO (ARGS) __attribute__ ((format (__printf__, m, n)))
#else
# include <varargs.h>
# define VA_START(va_list, var) va_start (va_list)
# define PRINTF_ALIST(msg) msg, va_alist
# define PRINTF_DCL(msg) char *msg; va_dcl  ////====here is the error
# define PRINTF_PROTO(ARGS, m, n) () __attribute__ ((format (__printf__, m, n)))
# define vfprintf(file, msg, args) \
    { \
      char *a0 = va_arg(args, char *); \
      char *a1 = va_arg(args, char *); \
      char *a2 = va_arg(args, char *); \
      char *a3 = va_arg(args, char *); \
      fprintf (file, msg, a0, a1, a2, a3); \
    }
#endif

...

void
warning (PRINTF_ALIST (msg))
     PRINTF_DCL (msg)   ///the use macro part
{
  va_list args;

  VA_START (args, msg);
  vwarning (msg, args);
  va_end (args);
}

static void
fatal (PRINTF_ALIST (msg))
     PRINTF_DCL (msg)
{
  va_list args;

  fprintf (stderr, "%s: ", progname);
  VA_START (args, msg);
  vfprintf (stderr, msg, args);
  va_end (args);
  fprintf (stderr, "\n");
  exit (FATAL_EXIT_CODE);
}

and my compiler shows this error for:

error: expected declaration specifiers before ‘va_dcl’
195 | # define PRINTF_DCL(msg) char *msg; va_dcl

when to define macro apply, it is like:

PRINTF_DCL (msg)

the source file similar like: https://cis.temple.edu/~ingargio/cis307/software/mico/cpp/cccp.c But in that file that code line is 199.

I don't know why there is ';' before va_dcl. And do not know how to fix it.

Upvotes: 0

Views: 515

Answers (1)

Potatoswatter
Potatoswatter

Reputation: 137770

va_dcl is an obsolete facility, used to declare variadic functions in language dialects dating to long before standardization. (Reference 1, 2)

I suspect that the compiler is going down the wrong path here. Try compiling with -DHAVE_VPRINTF on the command line.

Upvotes: 1

Related Questions