This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: #define vfprintf
- To: law at cygnus dot com
- Subject: Re: #define vfprintf
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Mon, 13 Apr 1998 10:34:05 -0400 (EDT)
- Cc: egcs at cygnus dot com
> From: Jeffrey A Law <law@hurl.cygnus.com>
>
> Unfortunately it is not safe to #define vfprintf with arguments.
>
> Consider what happens if a header file in /usr/include looks like
> this:
>
> extern vfprintf ();
>
> Some compilers (notably HPs) will give an error because you don't
> pass enough arguments to the "macro":
>
> cpp: "stdio.h", line 216: warning 2005: vfprintf: Too few
> parameters (1) to macr
>
> Jeff Law (law@cygnus.com)
Sorry I didn't get back to you sooner, I was unavailable last
week.
Since I hadn't introduced any new vfprintf code yet, I wasn't
sure what you meant until I bootstrapped the latest snapshot on hpux.
But now I see what you mean. The hpux compiler chokes on my recent
patch to cccp.c and cexp.y in which I moved the following existing code
higher up in those files:
> #if defined (__STDC__) && defined (HAVE_VPRINTF)
> # include <stdarg.h>
> # 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 PRINTF_ALIST(msg) msg, va_alist
> # define PRINTF_DCL(msg) char *msg; va_dcl
> # 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
None of the above code is new, just its position in the file
changed. The reason I did this is because certain other cc's have the
restriction that stdarg.h/varargs.h must appear before stdio.h.
However, this causes the conflict on hpux (probably any KNR stage1 cc)
between the macro and the prototype.
This problem will go away when I submit patches to integrate
vfprintf.c, because the vfprintf() macro in the above code won't be
needed then. But I won't be done with that very soon, due to my own
time constraints.
If we need a stopgap measure, the following patch will do the
trick. Let me know if you want me to install it or wait until
vfprintf.c and the associated autoconf hackery is ready.
--Kaveh
Mon Apr 13 10:35:19 1998 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* cccp.c: Define macro VFPRINTF() instead of vfprintf(). If
VFPRINTF() is defined, define vfprintf to VFPRINTF but only after
system headers are included.
* cexp.y: Likewise.
diff -rup orig/egcs-980406/gcc/cccp.c egcs-980406/gcc/cccp.c
--- orig/egcs-980406/gcc/cccp.c Mon Apr 6 10:01:23 1998
+++ egcs-980406/gcc/cccp.c Mon Apr 13 09:43:58 1998
@@ -29,7 +29,7 @@ Boston, MA 02111-1307, USA. */
# define PRINTF_ALIST(msg) msg, va_alist
# define PRINTF_DCL(msg) char *msg; va_dcl
# define PRINTF_PROTO(ARGS, m, n) () __attribute__ ((format (__printf__, m, n)))
-# define vfprintf(file, msg, args) \
+# define VFPRINTF(file, msg, args) \
{ \
char *a0 = va_arg(args, char *); \
char *a1 = va_arg(args, char *); \
@@ -56,6 +56,10 @@ typedef unsigned char U_CHAR;
#include "gansidecl.h"
#include "pcp.h"
+
+#ifdef VFPRINTF
+#define vfprintf VFPRINTF
+#endif
#ifndef GET_ENVIRONMENT
#define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME)
diff -rup orig/egcs-980406/gcc/cexp.y egcs-980406/gcc/cexp.y
--- orig/egcs-980406/gcc/cexp.y Mon Apr 6 10:01:24 1998
+++ egcs-980406/gcc/cexp.y Mon Apr 13 09:44:52 1998
@@ -38,7 +38,7 @@ Boston, MA 02111-1307, USA.
# define PRINTF_ALIST(msg) msg, va_alist
# define PRINTF_DCL(msg) char *msg; va_dcl
# define PRINTF_PROTO(ARGS, m, n) () __attribute__ ((format (__printf__, m, n)))
-# define vfprintf(file, msg, args) \
+# define VFPRINTF(file, msg, args) \
{ \
char *a0 = va_arg(args, char *); \
char *a1 = va_arg(args, char *); \
@@ -56,6 +56,10 @@ Boston, MA 02111-1307, USA.
#ifdef MULTIBYTE_CHARS
#include <locale.h>
+#endif
+
+#ifdef VFPRINTF
+#define vfprintf VFPRINTF
#endif
typedef unsigned char U_CHAR;
--
Kaveh R. Ghazi Project Manager / Custom Development
ghazi@caip.rutgers.edu Icon CMT Corp.