Re: [PATCH] Fix compiler warnings by using designated initializers - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: [PATCH] Fix compiler warnings by using designated initializers
Date
Msg-id 48173f3d-060a-4936-bfab-46ec30a813e5@eisentraut.org
Whole thread
In response to Re: [PATCH] Fix compiler warnings by using designated initializers  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [PATCH] Fix compiler warnings by using designated initializers
List pgsql-hackers
On 04.06.26 18:36, Tom Lane wrote:
> Zakariyah Ali <zakariyahali100@gmail.com> writes:
>> Use C99 designated initializers (.type = T_ErrorSaveContext) instead of the
>> standard initializer {T_ErrorSaveContext} when initializing ErrorSaveContext.
>> This avoids missing-field-initializers compiler warnings for the remaining fields of
>> the struct (e.g. error_occurred).
> 
> What compiler produces such warnings?  I'm not really eager to make
> invasive, more-typing-required changes like this, especially when
> it's not obvious that the modified code is any more correct.

I think -Wmissing-field-initializers was meant here.

It looks like all of the changes are of the form

-    ErrorSaveContext escontext = {T_ErrorSaveContext};
+    ErrorSaveContext escontext = {.type = T_ErrorSaveContext};

Maybe we could do this more elegantly and safer with a non-pointer 
variant of makeNode/newNode.

Like

#define initNode(_type_) ((_type_){.type = T_##_type_})

ErrorSaveContext escontext = initNode(ErrorSaveContext);

(Or something else instead of "init".)




pgsql-hackers by date:

Previous
From: "ZizhuanLiu X-MAN"
Date:
Subject: Re: Return value of XLogInsertRecord() for XLOG_SWITCH record
Next
From: Peter Eisentraut
Date:
Subject: Re: Fix missing semicolon in pl_gram.y for option_value rule