I am currently working on a project to get into more advanced concepts of C. One of the concepts I want to learn about is const-correctness, so I decided to make my entire codebase abide by this idea.
Say we have a function like this:
/*
* Creates and displays a window.
*
* Returns non-zero on failure, 0 on success.
*/
extern int window_create(
_In_z_ char const *const pz_title, /* window title */
uint32_t width, /* width in pixels */
uint32_t height, /* height in pixels */
bool isvsync, /* Should VSync be enabled? */
/*
* Pointer to a pointer to a "window" structure
* that will receive the freshly-created window.
* Must not be NULL.
*/
_Outptr_ struct window **pps_window
);
A window will be created, and the pointer pointed to by pps_window will then point to the newly-created window struct.
Now, should I enforce const-correctness on the window ** parameter as well? Like so:
struct window **const pps_window
The thing is, in my opinion, because the pointer to the pointer itself is passed-by-value anyway, wouldn't explicitly marking it as const be somewhat pointless because the caller does not have to care if the pointer-to-pointer copy on the stack gets modified, or would it still be good practice to add it nonetheless?