Skip to content

Update run-time-library-behavior.md - inaccurate initialisation of AFX_EXTENSION_MODULE structure#2612

Merged
colin-home merged 2 commits into
MicrosoftDocs:masterfrom
yury-fedorov:patch-1
Nov 23, 2020
Merged

Update run-time-library-behavior.md - inaccurate initialisation of AFX_EXTENSION_MODULE structure#2612
colin-home merged 2 commits into
MicrosoftDocs:masterfrom
yury-fedorov:patch-1

Conversation

@yury-fedorov
Copy link
Copy Markdown
Contributor

The first two parameters of the structure AFX_EXTENSION_MODULE are BOOL and HMODULE. So initialisation with = { NULL, NULL } is inaccurate: first NULL is FALSE (or 0 due to BOOL is defined as int). In fact this expression cannot be transformed to modern C++ equivalent = { nullptr, nullptr }.

struct AFX_EXTENSION_MODULE
{
BOOL bInitialized;
HMODULE hModule;
HMODULE hResource;
CRuntimeClass* pFirstSharedClass;
COleObjectFactory* pFirstSharedFactory;
};

The first two parameters of the structure AFX_EXTENSION_MODULE are BOOL and HMODULE. So initialization with = { NULL, NULL } is misleading: first NULL is FALSE (or 0 due to BOOL is defined as int). In fact this expression cannot be transformed to modern C++ equivalent = { nullptr, nullptr }.

struct AFX_EXTENSION_MODULE
{
    BOOL bInitialized;
    HMODULE hModule;
    HMODULE hResource;
    CRuntimeClass* pFirstSharedClass;
    COleObjectFactory* pFirstSharedFactory;
};
@PRMerger12
Copy link
Copy Markdown
Contributor

@yury-fedorov : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@colin-home
Copy link
Copy Markdown
Contributor

@yury-fedorov
I'm confused why any initialization is required at all. Aren't global statics zero-initialized by default? The struct AFX_EXTENSION_MODULE type is POD and has no constructor.

@yury-fedorov
Copy link
Copy Markdown
Contributor Author

yury-fedorov commented Nov 21, 2020 via email

Adjusting the code after the feedback.
@PRMerger16
Copy link
Copy Markdown
Contributor

@yury-fedorov : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@yury-fedorov
Copy link
Copy Markdown
Contributor Author

yury-fedorov commented Nov 21, 2020

@corob-msft Could you please take a look on the new simplified version based on your feedback?

Copy link
Copy Markdown
Contributor

@colin-home colin-home left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks!

@colin-home colin-home merged commit 14a02f1 into MicrosoftDocs:master Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants