Skip to content

Compiler: fix C compiler warnings - #588

Merged
bvdberg merged 1 commit into
c2lang:masterfrom
chqrlie:c-warnings
Oct 27, 2026
Merged

bvdberg merged 1 commit into
c2lang:masterfrom
chqrlie:c-warnings

Conversation

@chqrlie

@chqrlie chqrlie commented Oct 24, 2026

Copy link
Copy Markdown
Contributor
  • fix sizeof, countof and offsetof type as usize instead of u32
  • force builtin expression type in variable argument expressions
  • add shell scripts to extract C compiler diagnostics
  • fix compiler warnings on macOS (signed/unsigned comparisons and such)

@bvdberg

bvdberg commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

It indeed removes all the C build warnings on my system as well.

When I do 'make clean; make' I see a warning:

grep: output/*/cgen/build.log: No such file or directory

What I dont like is that:

u32 total = sizeof(X) + 10;

gives a conversion error. Sizeof(X) is a compile-time constant, so can just be the smallest thing it can be. It could even be u8 if needed. Having to cast all these things to some smaller type is nasty...

@chqrlie
chqrlie force-pushed the c-warnings branch 3 times, most recently from c3d59ea to 1919bcd Compare October 25, 2026 08:16
@chqrlie

chqrlie commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

It indeed removes all the C build warnings on my system as well.

I also fixed in bug in the OpenBSD build, there was a redundant extern keyword

When I do 'make clean; make' I see a warning:

grep: output/*/cgen/build.log: No such file or directory

I do not get this warning, maybe a different version of make, but I changed the Makefile so this cannot happen.

What I dont like is that:

u32 total = sizeof(X) + 10;

gives a conversion error. Sizeof(X) is a compile-time constant, so can just be the smallest thing it can be. It could even be u8 if needed. Having to cast all these things to some smaller type is nasty...

I do not get a conversion error for this code fragment. I even added a test case for it.

* add shell scripts to extract C compiler diagnostics
* fix compiler warnings on macOS (signed/unsigned comparisons and such)
* fix compiler warnings on OpenBSD (redundant extern keyword)
@chqrlie

chqrlie commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

I split the sizeof fix out from this commit into a separate PR sizeof.
This should make it easier to merge this one.

@bvdberg
bvdberg merged commit 2c80ef7 into c2lang:master Oct 27, 2026
5 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.

2 participants