bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with gl_VSNPRINTF_ZEROSIZE_C99 under Sun C++ compiler


From: Pádraig Brady
Subject: Re: Problems with gl_VSNPRINTF_ZEROSIZE_C99 under Sun C++ compiler
Date: Fri, 16 Jan 2009 10:42:55 +0000
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Albert Chin wrote:
> When gl_VSNPRINTF_ZEROSIZE_C99 is run under the Sun C++ compiler on a
> recent Solaris release, it fails because of:
>   static char buf[8] = "DEADBEEF";
> 
> The compiler complains with:
>   Error: Cannot use const char[9] to initialize char[8].
> 
> So, just replace `8' with `9'?
> 
> gl_SNPRINTF_SIZE1 will have the same problem.
> 

C99 states that the NUL is only copied if there's place,
whereas this will generate an error for c++ (not just Sun's compiler).

That code was added nearly 2 years ago:
http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commit;h=f227e78
so I'm not sure c++ is supported here at all?

In any case, since we don't actually care what size the buf is,
the number should probably be removed altogether. Patch attached.

cheers,
Pádraig.
>From a411aae0f32d1c179b25766015869e882255d840 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden>
Date: Fri, 16 Jan 2009 10:40:42 +0000
Subject: [PATCH] printf.m4: allow to run with c++

* m4/printf.m4: Remove redundant size specifier for buffers
initialised from strings. C99 supports sizes 1 less than
the string size when the NUL is not required, but c++ does not.
---
 m4/printf.m4 |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/m4/printf.m4 b/m4/printf.m4
index 4d10993..530a7ba 100644
--- a/m4/printf.m4
+++ b/m4/printf.m4
@@ -1142,7 +1142,7 @@ AC_DEFUN([gl_SNPRINTF_SIZE1],
 #include <stdio.h>
 int main()
 {
-  static char buf[8] = "DEADBEEF";
+  static char buf[] = "DEADBEEF";
   snprintf (buf, 1, "%d", 12345);
   return buf[1] != 'E';
 }],
@@ -1160,7 +1160,7 @@ dnl     
---------------------------------------------------------------------
 dnl     #include <stdio.h>
 dnl     int main()
 dnl     {
-dnl       static char buf[8] = "DEADBEEF";
+dnl       static char buf[] = "DEADBEEF";
 dnl       snprintf (buf, 0, "%d", 12345);
 dnl       return buf[0] != 'D';
 dnl     }
@@ -1181,7 +1181,7 @@ dnl       return ret;
 dnl     }
 dnl     int main()
 dnl     {
-dnl       static char buf[8] = "DEADBEEF";
+dnl       static char buf[] = "DEADBEEF";
 dnl       my_snprintf (buf, 0, "%d", 12345);
 dnl       return buf[0] != 'D';
 dnl     }
@@ -1209,7 +1209,7 @@ static int my_snprintf (char *buf, int size, const char 
*format, ...)
 }
 int main()
 {
-  static char buf[8] = "DEADBEEF";
+  static char buf[] = "DEADBEEF";
   my_snprintf (buf, 0, "%d", 12345);
   return buf[0] != 'D';
 }],
-- 
1.5.3.6


reply via email to

[Prev in Thread] Current Thread [Next in Thread]