Suppress MSVC C4996 warnings in implementation section#539
Open
shyraptor wants to merge 1 commit intoraysan5:masterfrom
Open
Suppress MSVC C4996 warnings in implementation section#539shyraptor wants to merge 1 commit intoraysan5:masterfrom
shyraptor wants to merge 1 commit intoraysan5:masterfrom
Conversation
The existing _CRT_SECURE_NO_WARNINGS define (line 361) does not work when CRT headers are already included before raygui.h — which is the common case when using raylib.h, since it pulls in <stdio.h> first. MSVC's CRT headers check _CRT_SECURE_NO_WARNINGS once at first include to decide whether to add __declspec(deprecated) to functions like fopen and sscanf. Once the include guard fires, the decision is permanent. Defining _CRT_SECURE_NO_WARNINGS later has no effect. Use #pragma warning(push/disable/pop) scoped to the RAYGUI_IMPLEMENTATION section to suppress C4996 at the call sites regardless of include order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When raygui.h is included after raylib.h (the common case), MSVC emits
C4996 warnings on every fopen/sscanf call inside the implementation section:
raygui already defines _CRT_SECURE_NO_WARNINGS (line 361) to prevent this,
but it has no effect when stdio.h was already pulled in by an earlier header.
MSVC's CRT decides at first include whether to mark these functions deprecated;
a later define cannot undo that.
This PR adds a #pragma warning(push/disable/pop) block around the
RAYGUI_IMPLEMENTATION section, which suppresses C4996 at the call site
regardless of include order. The suppression is scoped — it does not
leak into user code.
Tested on MSVC 19.44 (Visual Studio 2022 Build Tools).