After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 539957 - sun cc can not compile name assign a struct variable
sun cc can not compile name assign a struct variable
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Build system
git-master
Other opensolaris
: Normal blocker
: ---
Assigned To: Halton Huo
Derek Atkins
Depends on:
Blocks:
 
 
Reported: 2008-06-24 14:02 UTC by Halton Huo
Modified: 2018-06-29 22:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch for bug #539957 (23.19 KB, patch)
2008-06-24 15:20 UTC, Halton Huo
rejected Details | Review
new patch for bug #539957 (28.43 KB, patch)
2008-06-25 04:25 UTC, Halton Huo
committed Details | Review

Description Halton Huo 2008-06-24 14:02:24 UTC
I'm build gnucash trunk (r17246) with sun cc under Solaris, but get following
fails :

"Account.c", line 4476: non-constant initializer: op "NAME"
"Account.c", line 4476: syntax error before or at: :
"Account.c", line 4541: cannot recover from previous errors
cc: acomp failed for Account.c
Comment 1 Derek Atkins 2008-06-24 14:06:52 UTC
This construct is used everywhere in the source.

I suggest you just use GCC.
Comment 2 Halton Huo 2008-06-24 14:43:25 UTC
Yes, I know gcc works fine.
But it is better that other compiler expect gcc can build gnucash, isn't it?

If this is not a standard in C, I'll push sun compiler guys. So is it a standard?

Moreover, I'm writing the patch for this bug. Will offer you later.
Comment 3 Halton Huo 2008-06-24 15:20:44 UTC
Created attachment 113339 [details] [review]
patch for bug #539957
Comment 4 Derek Atkins 2008-06-24 19:35:58 UTC
While I agree that in general gnucash should work on any compiler, removing this particular construct is dangerous, particularly if the structure being initialized changes down the road.

With this initializer construct you can safely add a new structure member without requiring that you touch every usage of the structure.  Although it's unclear if the unassigned members are zero'd or not using this construct.   However, what it DOES allow is the structure members to be REORDERED without having to touch your usages, which allows for greater safety.

Comment 5 Halton Huo 2008-06-25 02:40:10 UTC
Checked with C99 standard, can we use "designated initializers" which is workable both on gcc and suncc. The patch will look likes:

Index: src/engine/Account.c
===================================================================
--- src/engine/Account.c	(revision 17250)
+++ src/engine/Account.c	(working copy)
@@ -4473,17 +4473,17 @@
 /* QofObject function implementation and registration */
 
 static QofObject account_object_def = {
-  interface_version:     QOF_OBJECT_VERSION,
-  e_type:                GNC_ID_ACCOUNT,
-  type_label:            "Account",
-  create:                (gpointer)xaccMallocAccount,
-  book_begin:            NULL,
-  book_end:              NULL,
-  is_dirty:              qof_collection_is_dirty,
-  mark_clean:            qof_collection_mark_clean,
-  foreach:               qof_collection_foreach,
-  printable:             (const char* (*)(gpointer)) xaccAccountGetName,
-  version_cmp:           (int (*)(gpointer,gpointer)) qof_instance_version_cmp,
+  .interface_version = QOF_OBJECT_VERSION,
+  .e_type            = GNC_ID_ACCOUNT,
+  .type_label        = "Account",
+  .create            = (gpointer)xaccMallocAccount,
+  .book_begin        = NULL,
+  .book_end          = NULL,
+  .is_dirty          = qof_collection_is_dirty,
+  .mark_clean        = qof_collection_mark_clean,
+  .foreach           = qof_collection_foreach,
+  .printable         = (const char* (*)(gpointer)) xaccAccountGetName,
+  .version_cmp       = (int (*)(gpointer,gpointer)) qof_instance_version_cmp,
 };
 
 gboolean xaccAccountRegister (void)


Comment 6 Derek Atkins 2008-06-25 03:44:12 UTC
I'll have to test that (because we're mostly using C90 constructs, not C99), but I THINK that gcc4 supports that.  I can't test gcc3 easily, but I dont particularly care about gcc3 anymore either.  So I think a patch like this would be acceptable.
Comment 7 Halton Huo 2008-06-25 04:25:37 UTC
Created attachment 113380 [details] [review]
new patch for bug #539957 

Rework patch with C99 "designated initializers", please check.
Comment 8 Andreas Köhler 2008-08-20 09:45:09 UTC
I will try to run some tests with older gcc versions and on Windows then.
Do not know about MACs.
Comment 9 Christian Stimming 2008-10-25 20:23:50 UTC
I think we should accept this into trunk. Maybe not 2.2-branch, but trunk should be fine.
Comment 10 Christian Stimming 2008-11-26 14:39:52 UTC
Committed to trunk, r17724. Thanks a lot!
Comment 11 Christian Stimming 2008-11-27 08:59:31 UTC
By they way, Windows/mingw with gcc3.4.2 compiles just fine with this change.
Comment 12 John Ralls 2018-06-29 22:06:06 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=539957. Please update any external references or bookmarks.