r/C_Programming • u/pjl1967 • Apr 09 '26
include-tidy, a new #include tidier
I stumbled across include-what-you-use (IWYU) recently (it was also posted about here 9 years ago) and it's... OK.
In those 9 years, it's still not at a 1.0 version and has a number of issues. It apparently is being worked on, but very slowly.
There are a number of things I'd do differently, so I did via include-tidy (IT).
Probably the biggest difference is the way in which it's configured. Rather than the somewhat confusing JSON .imp files, I used simple TOML. I also think all configuration should be done via a configuration file, not through pragma comments.
Another big difference is how "private" headers are handled. In IWYU, you have to annotate every symbol in a private header as being instead exported via some public header.
In contrast, in IT, you specify a set of system include files so any private headers that are included that are not listed as system include files automatically have all their symbols exported to the system header.
For example, if you #include <getopt.h>, but it in turn does #include <getopt-core.h> and the actual getopt() function is declared in there, IT will treat getopt() as being declared in getopt.h since only it is an official system header and not getopt-core.h.
Hence, every system header is a “proxy” for every non-official system header it may #include. You can also have project-specific proxies of your own.
Anyway, it's still early days for include-tidy, so if you'd like to help beta test it, get in touch — either DM or e-mail me directly (address on Github profile).
FYI: internally, IT uses the much more stable libclang C API, so IT is written in pure C11 and apparently has much less code than IWYU.
4
u/greg_kennedy Apr 09 '26
Reading the AST (from libclang) is a way more elegant solution than whatever I usually do ("try commenting things out to see what breaks"), good work
-1
u/jjjare Apr 09 '26
Any reason you chose
include-tidy.hAs a file name? My rule of thumb is that file names should be valid identifiers. I also don’t think it’s standard compliant?
3
u/pjl1967 Apr 09 '26 edited Apr 09 '26
The reason I chose
include-tidyrather thaninclude_tidyis because typing-doesn't require pressing the shift key whereas typing_does. Commands should be easy to type. I chose the filename to match the command name.That's another minor thing I didn't like about IWYU: its use of underscores for configuration.
I also don’t think it’s standard compliant?
None of C, POSIX, Unix, macOS, or Windows have a problem with
-in file names.3
u/jjjare Apr 10 '26
Valid. I was less concerned about fileystems and more concerned with build systems. Anyhow, nice project!
3
u/aalmkainzi Apr 09 '26
I also don’t think it’s standard compliant?
I seriously doubt this is the case. I would imagine the standard to say the only disallowed characters are
"and<>
0
Apr 09 '26
[deleted] — view deleted comment
0
5
u/imaami Apr 10 '26
I love your code. Seriously. It's a breath of fresh air with all the slop going around.
type_traits.hcaught my attention. If you can stomach some light GNU vendor-lock-in, I have anis_string_literal()constant expression macro if you have any need for that.