Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Anonymous struct trick with using does not play nicely with raw_union initialization.

Open JesseRMeyer opened this issue 1 week ago • 0 comments

Consider:

Surface_RGBA :: struct #raw_union {
	 //NOTE(Jesse): Reflect byte order for assumed window backing formats.
	using _: struct {
		B, G, R, A: u8, 
	},

	e: [4]u8,
}

Usage:

blah := Surface_RGBA{192, 182, 255, 0} // Error: Surface_RGBA ('struct #raw_union') compound literals are only allowed to contain 'field = value' elements

blah := Surface_RGBA{R=192, G=182, B=255, A=0} //Error: Surface_RGBA ('struct #raw_union') compound literals are only allowed to contain up to 1 'field = value' element, got 4 

blah := Surface_RGBA{e={192, 182, 255,0}} // Works but unreadable

"Anonymous" structs should be allowed to play nicely with raw_unions to better emulate their C/C++ counterparts.

JesseRMeyer avatar Dec 10 '25 22:12 JesseRMeyer