Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2020

Conversation

yury-fedorov
Copy link
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
Contributor

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

@colin-home
Copy link
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
Contributor Author

yury-fedorov commented Nov 21, 2020 via email

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

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

@yury-fedorov
Copy link
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
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