Using initializer without a cast?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



typedef struct MyItemType { double d; } MyItemType;

double Fun1(MyItemType mit)
{
	return mit.d;
}

int main(int argc, char* argv[])
{
	// This is ok. Works as expected. If I wanted initializer
	// to represent a different type, I would cast it.
	MyItemType mit1 = { 1.0 };
	MyItemType mit2 = { .d = 1.0 };
	
	// These require a cast.
	mit1 = (MyItemType){ 1.0 };
	mit2 = (MyItemType){ .d = 1.0 };
	Fun1((MyItemType){ 1.0 });
	Fun1((MyItemType){ .d = 1.0 });
}


Is there a way of doing initializers in second group without doing a cast?
Why can't GCC assume the type just like above?
Especially the function call, which is (effectively) just like
assigning to a newly declared auto variable?

Thanks.
BM



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux