git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Fix "identifier redeclared" compilation error with SUN cc

From
GOGuido Ostkamp <git@ostkamp.fastmail.fm>
Date
Nov 20, 2007, 17:28 UTC
Message-ID
<Pine.LNX.4.64.0711201823460.4280@bianca.dialin.t-online.de>
In-Reply-To
<7vhcjhl3ni.fsf@gitster.siamese.dyndns.org>
Hello Junio,
On Tue, 20 Nov 2007, Junio C Hamano wrote:
Show 14 quoted lines
> I knew it would work on Solaris with gcc and cc that do not understand 
> flexible array members, but I am a bit worried about other environments, 
> where flexible array members are properly supported.  They've been 
> happily using member[] but with the patch they suddenly start wasting a 
> cell.
>
> But we should do this sooner rather than later to find out any breakage, 
> and give people on platforms with a cc that supports flexible array 
> members and care about wasted memory enough time to send patches to 
> support their compiler in the way similar to how gcc is supported.
>
> But I cannot use your message with whitespace-broken patch (note 
> "format=flawed") and insufficient commit log message, which means I have 
> to do this myself.  Not tonight...

sorry for the whitespace-issues. I have attached the patch again with improved log message and will turn off format-flawed for this email.

Please let me know if this one is ok and feel free to fix it.
Log message starts here:
Fix "identifier redeclared" compilation error with SUN cc.
The problem is caused by incomplete arrays like
   struct foo {
     ...
     char last_member_that_is_flexible[];
   }

which cannot be handled by certain compilers. The solution is to change the last member to either

     char last_member_that_is_flexible[0]
or
     char last_member_that_is_flexible[1]

as required. Currently GNU CC can handle [] format for version 3 and later. Earlier versions need [0]. Non-GNU compiler use the safe form [1].

Signed-off-by: Guido Ostkamp <git@ostkamp.fastmail.fm>
---
  git-compat-util.h |   11 ++++++++++-
  1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 276a437..97759fd 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -4,11 +4,20 @@
  #define _FILE_OFFSET_BITS 64

  #ifndef FLEX_ARRAY
-#if defined(__GNUC__) && (__GNUC__ < 3)
+#if defined(__GNUC__)
+#if (__GNUC__ < 3)
  #define FLEX_ARRAY 0
  #else
  #define FLEX_ARRAY /* empty */
  #endif
+#else
+/* more cases we know we can use 0 or empty can come here */
+#endif
+#endif
+
+/* if still undefined, default to the safe, old fashioned way */
+#ifndef FLEX_ARRAY
+#define FLEX_ARRAY 1
  #endif

  #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
-- 
1.5.3.6.728.gea559
Previous: Junio C HamanoNext: Guido Ostkamp
Message 23 of 31 in “Fix Solaris Workshop Compiler issues”
  1. Fix Solaris Workshop Compiler issuesGuido Ostkamp, Nov 14, 2007
  2. Alex RiesenNov 14, 2007
  3. Junio C HamanoNov 14, 2007
  4. Guido OstkampNov 14, 2007
  5. Alex RiesenNov 14, 2007
  6. Björn SteinbrinkNov 15, 2007
  7. Junio C HamanoNov 15, 2007
  8. Björn SteinbrinkNov 15, 2007
  9. Junio C HamanoNov 15, 2007
  10. Björn SteinbrinkNov 15, 2007
  11. Fix "identifier redeclared" compilation error with SUN cc.Björn Steinbrink, Nov 15, 2007
  12. Guido OstkampNov 15, 2007
  13. Junio C HamanoNov 15, 2007
  14. Guido OstkampNov 15, 2007
  15. Add mkdtemp() workaround for Sun Solaris 10Guido Ostkamp, Nov 16, 2007
  16. [RFH] Solaris portabilityJunio C Hamano, Nov 17, 2007
  17. Guido OstkampNov 18, 2007
  18. Junio C HamanoNov 18, 2007
  19. Junio C HamanoNov 16, 2007
  20. Björn SteinbrinkNov 16, 2007
  21. Fix "identifier redeclared" compilation error with SUN ccGuido Ostkamp, Nov 19, 2007
  22. Junio C HamanoNov 20, 2007
  23. Guido OstkampNov 20, 2007
  24. Guido OstkampNov 20, 2007
  25. Martin MaresNov 20, 2007
  26. Junio C HamanoNov 20, 2007
  27. Martin MaresNov 20, 2007
  28. Linus TorvaldsNov 15, 2007
  29. David KastrupNov 15, 2007
  30. Linus TorvaldsNov 15, 2007
  31. Junio C HamanoNov 15, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.