Skip to content

Fix/c formatting - #275

Merged
marchc1 merged 3 commits into
SourceDotNET:mainfrom
spacevx:fix/c-formatting
Nov 20, 2026
Merged

marchc1 merged 3 commits into
SourceDotNET:mainfrom
spacevx:fix/c-formatting

Conversation

@spacevx

@spacevx spacevx commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread Source.Common/CFormatting.cs Outdated
default: throw new NotImplementedException();
[UnscopedRef]
public ref ScanF Read(out int i) {
Unsafe.SkipInit(out i);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why SkipInit and not setting it to default? Is this how the original works? I believe it would just zero it out...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, C doesn't zero them, it leaves them untouched Border.ApplySchemeSettings use it/rely on this (original):

GetInset(out int left, out int top, out int right, out int bottom);
new ScanF(insetString, "%d %d %d %d").Read(out left).Read(out top).Read(out right).Read(out bottom);
SetInset(left, top, right, bottom);

For example, here right and bottom keep their values

#include <stdio.h>

int main(void)
{
        int left = 11, top = 22, right = 33, bottom = 44;
        int n = sscanf("2 2", "%d %d %d %d", &left, &top, &right, &bottom);
        printf("sscanf(\"2 2\", \"%%d %%d %%d %%d\") returned %d\n", n);
        printf("left=%d top=%d right=%d bottom=%d\n", left, top, right, bottom);
        return 0;
}
image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would say that we should have out vs ref functions instead, separated. So ref requires initialization and out does not. I just don't like breaking the out semantics

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Read(out) now zeroes & ReadOrKeep(ref) keeps C leave-untouched behaviour (where the C++ relies on it)

@marchc1

marchc1 commented Nov 17, 2026

Copy link
Copy Markdown
Member

also merge conflicts now

@spacevx

spacevx commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

also merge conflicts now

Should be good

Comment thread Source.Common.Tests/CFormattingTests.cs Resolved
@marchc1
marchc1 merged commit d908b3a into SourceDotNET:main Nov 20, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants