Using Arrays with Unions or Structures Not Working

CDev-8220 240 Reputation points
2025-03-08T03:02:37.23+00:00

I'm trying to use arrays, with CheckFeatureSupport, rather than check each feature with separate code.

I am using different types of elements, so I have to use either union or struct.

The problems I am having, is the array of the struct does not point to the element, and the array of the union succeeds, only if I have less than six elements.

Difficult to explain.

Here is the code:

	union mixedArray {
		D3D11_FEATURE_DATA_THREADING ma_threading{};
		/* a union can have at most, one field initializer */
		D3D11_FEATURE_DATA_DOUBLES ma_doubles;
		D3D11_FEATURE_DATA_FORMAT_SUPPORT ma_format_support;
		D3D11_FEATURE_DATA_FORMAT_SUPPORT2 ma_format_support2;
		D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS ma_d3d10x_hardware_options;
		/*D3D11_FEATURE_DATA_D3D11_OPTIONS ma_d3d11_options;
		D3D11_FEATURE_DATA_ARCHITECTURE_INFO ma_architecture_info;
		D3D11_FEATURE_DATA_D3D9_OPTIONS ma_d3d9_options;
		D3D11_FEATURE_DATA_SHADER_MIN_PRECISION_SUPPORT ma_shader_min_precision_support;
		D3D11_FEATURE_DATA_D3D9_SHADOW_SUPPORT ma_d3d9_shadow_support;
		D3D11_FEATURE_DATA_D3D11_OPTIONS1 ma_d3d11_options1;
		D3D11_FEATURE_DATA_D3D9_SIMPLE_INSTANCING_SUPPORT ma_d3d9_simple_instancing_support;
		D3D11_FEATURE_DATA_MARKER_SUPPORT ma_marker_support;
		D3D11_FEATURE_DATA_D3D9_OPTIONS1 ma_d3d9_options1;
		D3D11_FEATURE_DATA_D3D11_OPTIONS2 ma_d3d11_options2;
		D3D11_FEATURE_DATA_D3D11_OPTIONS3 ma_d3d11_options3;
		D3D11_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT ma_gpu_virtual_address_support;
		D3D11_FEATURE_DATA_D3D11_OPTIONS4 ma_d3d11_options4;
		D3D11_FEATURE_DATA_SHADER_CACHE ma_shader_cache;
		D3D11_FEATURE_DATA_D3D11_OPTIONS5 ma_d3d11_options5;
		D3D11_FEATURE_DATA_DISPLAYABLE ma_displayable;*/
	};
	mixedArray ma[21]{};

// in a for loop
hr = m_D3D11Device->CheckFeatureSupport(
	m_D3D11Features[0], 
	&ma[0],
	sizeof(ma[0])
);
if (SUCCEEDED(hr)) {
	text = "\nSUCCESS!\n"; writingString(text);
}
else {
	text = "\nFAILURE!\n"; writingString(text);
}

When I add the other items, the check fails.

Changing it to struct, does not allow me to use ma[0].

I have to manually do ma[0].ma_threading, which isn't useful to me.

Any suggestions?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,742 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.