My understanding is that if a pointer points to something that is read and written, that is, "inout" then, by definition it cannot be "const" (because of "out") yet, there are prototypes in the C headers that specify parameters as "inout const" which doesn't make sense to me. For intance:
EXTERN_C _Check_return_ NTSTATUS APIENTRY D3DKMTEnumAdapters2(_Inout_ CONST D3DKMT_ENUMADAPTERS2*);
As I mentioned above, I don't see how the parameter can be "const" given that it's also "out".
Am I misunderstanding something or is that definition incorrect ?
Thank you for your help.
`
In theory, there is nothing to prevent an argument declared as
_Inout_having theconstqualifier, when that argument is a pointer to a structure.For instance, the argument in the call to
D3DKMTEnumAdapters2is a pointer to aD3DKMT_ENUMADAPTERS2structure, which is defined as follows:Now, if the
pAdaptersmember were a pre-allocated array ofD3DKMT_ADAPTERINFOobjects (of size specified in theNumAdaptersmember), and all the function did was to fill that data array with the relevant information for each adapter, then the passed structure itself would not have been modified – so there is no conflict with theconstqualifier on the argument.However, from the documentation for
D3DKMTEnumAdapters2, it appears that theNumAdapersmember itself is also changed (potentially):Thus, according to that paragraph, the
constattribute will be violated when the function is called with aNULLvalue for thepAdaptersmember of the passed (pointed-to) structure.Note that the linked documentation also implies that the
NumAdaptersmember is modified, even when a non-nullpAdaptersvalue is given (emphasis mine):