GNOME Bugzilla – Bug 539957
sun cc can not compile name assign a struct variable
Last modified: 2018-06-29 22:06:06 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
This construct is used everywhere in the source. I suggest you just use GCC.
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.
Created attachment 113339 [details] [review] patch for bug #539957
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.
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)
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.
Created attachment 113380 [details] [review] new patch for bug #539957 Rework patch with C99 "designated initializers", please check.
I will try to run some tests with older gcc versions and on Windows then. Do not know about MACs.
I think we should accept this into trunk. Maybe not 2.2-branch, but trunk should be fine.
Committed to trunk, r17724. Thanks a lot!
By they way, Windows/mingw with gcc3.4.2 compiles just fine with this change.
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.