c++ - IID_PPV_ARGS and Dereferencing NULL -


a project i'm working on , msdn documentation has code such this:

ifileopendialog *pfileopen; iid_ppv_args(&pfileopen) 

where iid_ppv_args is:

#define iid_ppv_args(pptype) __uuidof(**(pptype)), iid_ppv_args_helper(pptype) 

my question **(pptype) part. wouldn't end dereferencing null or unitialized pointer? why work?

__uuidof() proprietary microsoft extension, compiler knows how deal with. it's evaluated @ compile time, not @ run time.

the compiler attempts , substitute uuid given interface. interface declares uuid using __declspec(uuid("...")) extension. if compiler can't find uuid, build fail. no pointers dereferenced @ run time.

pptype set ifileopendialog**, *(pptype) ifileopendialog* , **(pptype) ifileopendialog. such, __uuidof(**(pptype)) evaluated __uuidof(ifileopendialog) @ compile time.

it's same doing this:

char* ptr = nullptr; size_t charsize = sizeof(*ptr); 

sizeof(*ptr) evaluated sizeof(char) @ compile time, though ptr null.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -