September 8th, 2006

Const pointers: Logical consequences

Consider this follow-up question to the question from last time:

When I call the PropertySheet function, can I assume that the phpage field of the PROPSHEETHEADER structure will not be modified?

If we take a look at the declaration of the PropertySheet function, we see that it reads like this:

typedef const PROPSHEETHEADERA *LPCPROPSHEETHEADERA;
typedef const PROPSHEETHEADERW *LPCPROPSHEETHEADERW;
WINCOMMCTRLAPI INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA);
WINCOMMCTRLAPI INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW);

Go past all the function declaration specification goo and look at the parameter list. It’s a const pointer to a PROPSHEETHEADER structure (either ANSI or Unicode, depending on which flavor of the PropertySheet function you’re calling).

One of the rules for const pointers is that you can read from them but you cannot write to them. Consequently, the PropertySheet function is not allowed to modify the PROPSHEETHEADER structure. Assuming your code doesn’t modify the PROPSHEETHEADER yourself, any value on exit from the function will be the same as the value it had on entry.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.