r18755 - gnucash/trunk/src/engine - MSVC compatibility: Microsoft doesn't have C99 "designated initializers".

Christian Stimming cstim at code.gnucash.org
Sat Feb 27 13:41:50 EST 2010


Author: cstim
Date: 2010-02-27 13:41:49 -0500 (Sat, 27 Feb 2010)
New Revision: 18755
Trac: http://svn.gnucash.org/trac/changeset/18755

Modified:
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/SX-book.c
   gnucash/trunk/src/engine/SchedXaction.c
   gnucash/trunk/src/engine/Split.c
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/gnc-budget.c
   gnucash/trunk/src/engine/gnc-commodity.c
   gnucash/trunk/src/engine/gnc-lot.c
   gnucash/trunk/src/engine/gnc-pricedb.c
Log:
MSVC compatibility: Microsoft doesn't have C99 "designated initializers".

Those were introduced in r17724, bug#539957, but apparently this
C99 is not supported by MSVC and won't be for some time to come.
Hence, for MSVC we need the workaround to define a macro that will
shadow the member names. However, the initialization itself works
fine and non-MSVC code is unchanged, so I think we can live with that.

Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2010-02-27 18:41:28 UTC (rev 18754)
+++ gnucash/trunk/src/engine/Account.c	2010-02-27 18:41:49 UTC (rev 18755)
@@ -4674,19 +4674,25 @@
 
 /* ================================================================ */
 /* QofObject function implementation and registration */
-
+#ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+# define DI(x) /* */
+#else
+# define DI(x) x
+#endif
 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,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_ACCOUNT,
+  DI(.type_label        =) "Account",
+  DI(.create            =) (gpointer)xaccMallocAccount,
+  DI(.book_begin        =) NULL,
+  DI(.book_end          =) NULL,
+  DI(.is_dirty          =) qof_collection_is_dirty,
+  DI(.mark_clean        =) qof_collection_mark_clean,
+  DI(.foreach           =) qof_collection_foreach,
+  DI(.printable         =) (const char* (*)(gpointer)) xaccAccountGetName,
+  DI(.version_cmp       =) (int (*)(gpointer,gpointer)) qof_instance_version_cmp,
 };
 
 gboolean xaccAccountRegister (void)

Modified: gnucash/trunk/src/engine/SX-book.c
===================================================================
--- gnucash/trunk/src/engine/SX-book.c	2010-02-27 18:41:28 UTC (rev 18754)
+++ gnucash/trunk/src/engine/SX-book.c	2010-02-27 18:41:49 UTC (rev 18755)
@@ -161,17 +161,24 @@
   g_list_free(descendants);
 }
 
+#ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+# define DI(x) /* */
+#else
+# define DI(x) x
+#endif
 static QofObject sxtg_object_def = 
 {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_SXTG,
-  .type_label        = "Scheduled Transaction Templates",
-  .book_begin        = sxtg_book_begin,
-  .book_end          = sxtg_book_end,
-  .is_dirty          = sxtg_is_dirty,
-  .mark_clean        = sxtg_mark_clean,
-  .foreach           = NULL,
-  .printable         = NULL,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_SXTG,
+  DI(.type_label        =) "Scheduled Transaction Templates",
+  DI(.book_begin        =) sxtg_book_begin,
+  DI(.book_end          =) sxtg_book_end,
+  DI(.is_dirty          =) sxtg_is_dirty,
+  DI(.mark_clean        =) sxtg_mark_clean,
+  DI(.foreach           =) NULL,
+  DI(.printable         =) NULL,
 };
 
 /* ====================================================================== */
@@ -307,32 +314,32 @@
 
 static QofObject sxes_object_def =
 {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_SXES,
-  .type_label        = "Scheduled Transactions List",
-  .create            = NULL,
-  .book_begin        = book_sxes_setup,
-  .book_end          = book_sxes_end,
-  .is_dirty          = book_sxlist_notsaved,
-  .mark_clean        = book_sxns_mark_saved,
-  .foreach           = NULL,
-  .printable         = NULL,
-  .version_cmp       = NULL
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_SXES,
+  DI(.type_label        =) "Scheduled Transactions List",
+  DI(.create            =) NULL,
+  DI(.book_begin        =) book_sxes_setup,
+  DI(.book_end          =) book_sxes_end,
+  DI(.is_dirty          =) book_sxlist_notsaved,
+  DI(.mark_clean        =) book_sxns_mark_saved,
+  DI(.foreach           =) NULL,
+  DI(.printable         =) NULL,
+  DI(.version_cmp       =) NULL
 };
   
 static QofObject sxtt_object_def = 
 {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_SXTT,
-  .type_label        = "Scheduled Transaction Templates",
-  .create            = NULL,
-  .book_begin        = NULL,
-  .book_end          = NULL,
-  .is_dirty          = NULL,
-  .mark_clean        = NULL,
-  .foreach           = NULL,
-  .printable         = NULL,
-  .version_cmp       = NULL,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_SXTT,
+  DI(.type_label        =) "Scheduled Transaction Templates",
+  DI(.create            =) NULL,
+  DI(.book_begin        =) NULL,
+  DI(.book_end          =) NULL,
+  DI(.is_dirty          =) NULL,
+  DI(.mark_clean        =) NULL,
+  DI(.foreach           =) NULL,
+  DI(.printable         =) NULL,
+  DI(.version_cmp       =) NULL,
 };
 
 gboolean 

Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c	2010-02-27 18:41:28 UTC (rev 18754)
+++ gnucash/trunk/src/engine/SchedXaction.c	2010-02-27 18:41:49 UTC (rev 18755)
@@ -859,19 +859,26 @@
    return sx->deferredList;
 }
 
+#ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+# define DI(x) /* */
+#else
+# define DI(x) x
+#endif
 static QofObject SXDesc = 
 {
-	.interface_version = QOF_OBJECT_VERSION,
-	.e_type            = GNC_SX_ID,
-	.type_label        = "Scheduled Transaction",
-	.create            = (gpointer)xaccSchedXactionMalloc,
-	.book_begin        = NULL,
-	.book_end          = NULL,
-	.is_dirty          = qof_collection_is_dirty,
-	.mark_clean        = qof_collection_mark_clean,
-	.foreach           = qof_collection_foreach,
-	.printable         = NULL,
-	.version_cmp       = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+	DI(.interface_version =) QOF_OBJECT_VERSION,
+	DI(.e_type            =) GNC_SX_ID,
+	DI(.type_label        =) "Scheduled Transaction",
+	DI(.create            =) (gpointer)xaccSchedXactionMalloc,
+	DI(.book_begin        =) NULL,
+	DI(.book_end          =) NULL,
+	DI(.is_dirty          =) qof_collection_is_dirty,
+	DI(.mark_clean        =) qof_collection_mark_clean,
+	DI(.foreach           =) qof_collection_foreach,
+	DI(.printable         =) NULL,
+	DI(.version_cmp       =) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
 };
 
 gboolean

Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c	2010-02-27 18:41:28 UTC (rev 18754)
+++ gnucash/trunk/src/engine/Split.c	2010-02-27 18:41:49 UTC (rev 18755)
@@ -1780,18 +1780,25 @@
 
 /* Hook into the QofObject registry */
 
+#ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+# define DI(x) /* */
+#else
+# define DI(x) x
+#endif
 static QofObject split_object_def = {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_SPLIT,
-  .type_label        = "Split",
-  .create            = (gpointer)xaccMallocSplit,
-  .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)) xaccSplitGetMemo,
-  .version_cmp       = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_SPLIT,
+  DI(.type_label        =) "Split",
+  DI(.create            =) (gpointer)xaccMallocSplit,
+  DI(.book_begin        =) NULL,
+  DI(.book_end          =) NULL,
+  DI(.is_dirty          =) qof_collection_is_dirty,
+  DI(.mark_clean        =) qof_collection_mark_clean,
+  DI(.foreach           =) qof_collection_foreach,
+  DI(.printable         =) (const char* (*)(gpointer)) xaccSplitGetMemo,
+  DI(.version_cmp       =) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
 };
 
 static gpointer 

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2010-02-27 18:41:28 UTC (rev 18754)
+++ gnucash/trunk/src/engine/Transaction.c	2010-02-27 18:41:49 UTC (rev 18755)
@@ -2028,19 +2028,27 @@
 \********************************************************************/
 /* QofObject function implementation */
 
+#ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+# define DI(x) /* */
+#else
+# define DI(x) x
+#endif
+
 /* Hook into the QofObject registry */
 static QofObject trans_object_def = {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_TRANS,
-  .type_label        = "Transaction",
-  .create            = (gpointer)xaccMallocTransaction,
-  .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)) xaccTransGetDescription,
-  .version_cmp       = (int (*)(gpointer,gpointer)) qof_instance_version_cmp,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_TRANS,
+  DI(.type_label        =) "Transaction",
+  DI(.create            =) (gpointer)xaccMallocTransaction,
+  DI(.book_begin        =) NULL,
+  DI(.book_end          =) NULL,
+  DI(.is_dirty          =) qof_collection_is_dirty,
+  DI(.mark_clean        =) qof_collection_mark_clean,
+  DI(.foreach           =) qof_collection_foreach,
+  DI(.printable         =) (const char* (*)(gpointer)) xaccTransGetDescription,
+  DI(.version_cmp       =) (int (*)(gpointer,gpointer)) qof_instance_version_cmp,
 };
 
 static gboolean

Modified: gnucash/trunk/src/engine/gnc-budget.c
===================================================================
--- gnucash/trunk/src/engine/gnc-budget.c	2010-02-27 18:41:28 UTC (rev 18754)
+++ gnucash/trunk/src/engine/gnc-budget.c	2010-02-27 18:41:49 UTC (rev 18755)
@@ -600,20 +600,28 @@
     return bgt;
 }
 
+#ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+# define DI(x) /* */
+#else
+# define DI(x) x
+#endif
+
 /* Define the QofObject. */
 static QofObject budget_object_def =
 {
-    .interface_version = QOF_OBJECT_VERSION,
-    .e_type            = GNC_ID_BUDGET,
-    .type_label        = "Budget",
-    .create            = (gpointer)gnc_budget_new,
-    .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)) gnc_budget_get_name,
-    .version_cmp       = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+    DI(.interface_version =) QOF_OBJECT_VERSION,
+    DI(.e_type            =) GNC_ID_BUDGET,
+    DI(.type_label        =) "Budget",
+    DI(.create            =) (gpointer)gnc_budget_new,
+    DI(.book_begin        =) NULL,
+    DI(.book_end          =) NULL,
+    DI(.is_dirty          =) qof_collection_is_dirty,
+    DI(.mark_clean        =) qof_collection_mark_clean,
+    DI(.foreach           =) qof_collection_foreach,
+    DI(.printable         =) (const char* (*)(gpointer)) gnc_budget_get_name,
+    DI(.version_cmp       =) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
 };
 
 

Modified: gnucash/trunk/src/engine/gnc-commodity.c
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.c	2010-02-27 18:41:28 UTC (rev 18754)
+++ gnucash/trunk/src/engine/gnc-commodity.c	2010-02-27 18:41:49 UTC (rev 18755)
@@ -2312,30 +2312,37 @@
  ********************************************************************/
 /* QofObject function implementation and registration */
 
+#ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+# define DI(x) /* */
+#else
+# define DI(x) x
+#endif
 static QofObject commodity_object_def = 
 {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_COMMODITY,
-  .type_label        = "Commodity",
-  .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)) gnc_commodity_get_fullname,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_COMMODITY,
+  DI(.type_label        =) "Commodity",
+  DI(.book_begin        =) NULL,
+  DI(.book_end          =) NULL,
+  DI(.is_dirty          =) qof_collection_is_dirty,
+  DI(.mark_clean        =) qof_collection_mark_clean,
+  DI(.foreach           =) qof_collection_foreach,
+  DI(.printable         =) (const char* (*)(gpointer)) gnc_commodity_get_fullname,
 };
 
 static QofObject namespace_object_def = 
 {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_COMMODITY_NAMESPACE,
-  .type_label        = "Namespace",
-  .book_begin        = NULL,
-  .book_end          = NULL,
-  .is_dirty          = NULL,
-  .mark_clean        = NULL,
-  .foreach           = NULL,
-  .printable         = NULL,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_COMMODITY_NAMESPACE,
+  DI(.type_label        =) "Namespace",
+  DI(.book_begin        =) NULL,
+  DI(.book_end          =) NULL,
+  DI(.is_dirty          =) NULL,
+  DI(.mark_clean        =) NULL,
+  DI(.foreach           =) NULL,
+  DI(.printable         =) NULL,
 };
 
 static void 
@@ -2370,17 +2377,17 @@
 
 static QofObject commodity_table_object_def = 
 {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_COMMODITY_TABLE,
-  .type_label        = "CommodityTable",
-  .create            = NULL,
-  .book_begin        = commodity_table_book_begin,
-  .book_end          = commodity_table_book_end,
-  .is_dirty          = qof_collection_is_dirty,
-  .mark_clean        = qof_collection_mark_clean,
-  .foreach           = NULL,
-  .printable         = NULL,
-  .version_cmp       = NULL,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_COMMODITY_TABLE,
+  DI(.type_label        =) "CommodityTable",
+  DI(.create            =) NULL,
+  DI(.book_begin        =) commodity_table_book_begin,
+  DI(.book_end          =) commodity_table_book_end,
+  DI(.is_dirty          =) qof_collection_is_dirty,
+  DI(.mark_clean        =) qof_collection_mark_clean,
+  DI(.foreach           =) NULL,
+  DI(.printable         =) NULL,
+  DI(.version_cmp       =) NULL,
 };
 
 gboolean 

Modified: gnucash/trunk/src/engine/gnc-lot.c
===================================================================
--- gnucash/trunk/src/engine/gnc-lot.c	2010-02-27 18:41:28 UTC (rev 18754)
+++ gnucash/trunk/src/engine/gnc-lot.c	2010-02-27 18:41:49 UTC (rev 18755)
@@ -610,19 +610,26 @@
 
 /* ============================================================= */
 
+#ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+# define DI(x) /* */
+#else
+# define DI(x) x
+#endif
 static QofObject gncLotDesc =
 {
-    .interface_version = QOF_OBJECT_VERSION,
-    .e_type            = GNC_ID_LOT,
-    .type_label        = "Lot",
-    .create            = (gpointer)gnc_lot_new,
-    .book_begin        = NULL,
-    .book_end          = NULL,
-    .is_dirty          = qof_collection_is_dirty,
-    .mark_clean        = qof_collection_mark_clean,
-    .foreach           = qof_collection_foreach,
-    .printable         = NULL,
-    .version_cmp       = (int (*)(gpointer,gpointer))qof_instance_version_cmp,
+    DI(.interface_version =) QOF_OBJECT_VERSION,
+    DI(.e_type            =) GNC_ID_LOT,
+    DI(.type_label        =) "Lot",
+    DI(.create            =) (gpointer)gnc_lot_new,
+    DI(.book_begin        =) NULL,
+    DI(.book_end          =) NULL,
+    DI(.is_dirty          =) qof_collection_is_dirty,
+    DI(.mark_clean        =) qof_collection_mark_clean,
+    DI(.foreach           =) qof_collection_foreach,
+    DI(.printable         =) NULL,
+    DI(.version_cmp       =) (int (*)(gpointer,gpointer))qof_instance_version_cmp,
 };
 
 

Modified: gnucash/trunk/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/trunk/src/engine/gnc-pricedb.c	2010-02-27 18:41:28 UTC (rev 18754)
+++ gnucash/trunk/src/engine/gnc-pricedb.c	2010-02-27 18:41:49 UTC (rev 18755)
@@ -2479,34 +2479,41 @@
   return buff;
 }
 
+#ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+# define DI(x) /* */
+#else
+# define DI(x) x
+#endif
 static QofObject price_object_def =
 {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_PRICE,
-  .type_label        = "Price",
-  .create            = price_create,
-  .book_begin        = NULL,
-  .book_end          = NULL,
-  .is_dirty          = qof_collection_is_dirty,
-  .mark_clean        = qof_collection_mark_clean,
-  .foreach           = price_foreach,
-  .printable         = price_printable,
-  .version_cmp       = NULL,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_PRICE,
+  DI(.type_label        =) "Price",
+  DI(.create            =) price_create,
+  DI(.book_begin        =) NULL,
+  DI(.book_end          =) NULL,
+  DI(.is_dirty          =) qof_collection_is_dirty,
+  DI(.mark_clean        =) qof_collection_mark_clean,
+  DI(.foreach           =) price_foreach,
+  DI(.printable         =) price_printable,
+  DI(.version_cmp       =) NULL,
 };
 
 static QofObject pricedb_object_def =
 {
-  .interface_version = QOF_OBJECT_VERSION,
-  .e_type            = GNC_ID_PRICEDB,
-  .type_label        = "PriceDB",
-  .create            = NULL,
-  .book_begin        = pricedb_book_begin,
-  .book_end          = pricedb_book_end,
-  .is_dirty          = qof_collection_is_dirty,
-  .mark_clean        = qof_collection_mark_clean,
-  .foreach           = NULL,
-  .printable         = NULL,
-  .version_cmp       = NULL,
+  DI(.interface_version =) QOF_OBJECT_VERSION,
+  DI(.e_type            =) GNC_ID_PRICEDB,
+  DI(.type_label        =) "PriceDB",
+  DI(.create            =) NULL,
+  DI(.book_begin        =) pricedb_book_begin,
+  DI(.book_end          =) pricedb_book_end,
+  DI(.is_dirty          =) qof_collection_is_dirty,
+  DI(.mark_clean        =) qof_collection_mark_clean,
+  DI(.foreach           =) NULL,
+  DI(.printable         =) NULL,
+  DI(.version_cmp       =) NULL,
 };
 
 gboolean



More information about the gnucash-changes mailing list