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: Bruno Haible
Subject: Re: Problems with gl_VSNPRINTF_ZEROSIZE_C99 under Sun C++ compiler
Date: Fri, 16 Jan 2009 12:23:59 +0100
User-agent: KMail/1.9.9

Pádraig Brady wrote:
> 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).

Thanks for explaining. I was confused about when this special rule holds.

> In any case, since we don't actually care what size the buf is

I find the code clearer if the array's size is explicitly written down.
Committed this:


2009-01-16  Bruno Haible  <address@hidden>

        * m4/printf.m4 (gl_SNPRINTF_SIZE1, gl_VSNPRINTF_ZEROSIZE_C99): Use an
        array initializer syntax that also works in C++ mode.
        Reported by Albert Chin <address@hidden>.

--- m4/printf.m4.orig   2009-01-16 12:19:36.000000000 +0100
+++ m4/printf.m4        2009-01-16 12:19:10.000000000 +0100
@@ -1,4 +1,4 @@
-# printf.m4 serial 26
+# printf.m4 serial 27
 dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -1142,7 +1142,7 @@
 #include <stdio.h>
 int main()
 {
-  static char buf[8] = "DEADBEEF";
+  static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
   snprintf (buf, 1, "%d", 12345);
   return buf[1] != 'E';
 }],
@@ -1160,7 +1160,7 @@
 dnl     #include <stdio.h>
 dnl     int main()
 dnl     {
-dnl       static char buf[8] = "DEADBEEF";
+dnl       static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
 dnl       snprintf (buf, 0, "%d", 12345);
 dnl       return buf[0] != 'D';
 dnl     }
@@ -1181,7 +1181,7 @@
 dnl     }
 dnl     int main()
 dnl     {
-dnl       static char buf[8] = "DEADBEEF";
+dnl       static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
 dnl       my_snprintf (buf, 0, "%d", 12345);
 dnl       return buf[0] != 'D';
 dnl     }
@@ -1209,7 +1209,7 @@
 }
 int main()
 {
-  static char buf[8] = "DEADBEEF";
+  static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
   my_snprintf (buf, 0, "%d", 12345);
   return buf[0] != 'D';
 }],




reply via email to

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