This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Using initializer without a cast?


Hi!

On Mon, Apr 09, 2018 at 11:46:09PM +0200, Bostjan Mihoric wrote:
> 	// These require a cast.
> 	mit1 = (MyItemType){ 1.0 };
> 	mit2 = (MyItemType){ .d = 1.0 };
> 	Fun1((MyItemType){ 1.0 });
> 	Fun1((MyItemType){ .d = 1.0 });

Those aren't casts, those are compound literals.

> Is there a way of doing initializers in second group without doing a cast?
> Why can't GCC assume the type just like above?

Because that's not how C works.  Sorry.

(This is not a question about GCC but about C, and so it is off-topic
for this list).


Segher


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]