This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Using initializer without a cast?
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Bostjan Mihoric <ccompletion at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 9 Apr 2018 17:10:50 -0500
- Subject: Re: Using initializer without a cast?
- References: <CACp5gDUnX0xDFGxLU251a2BmiqWJfqtNi_eSE2hs=HWvLf9u0g@mail.gmail.com>
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