Live data from Hacker News

Large single compilation-unit C programs (2006)

people.csail.mit.edu

11–20 of 23 posts

Re: Large single compilation-unit C programs (2006)

#12

Earlier quoted context omitted.

The preprocessor doesn't remove comments and at least in clang, comments are parsed into the AST.

Well, according to C99, it should. Section "5.1.1.2 Translation phases" says (in phase 3): "Each comment is replaced by one space character." Edit: just checked and clang behaves just like gcc with -E. Maybe you didn't mean comments but preprocessor directives?

Clang, like GCC, has -C and -CC flags to preserve comments during preprocessing. However, these are really flags for the underlying preprocessor. Your parent might be thinking of some application of the Clang frontend that does not run preprocessing. For example, clang-format will probably not want to preprocess the code nor strip out comments.

Re: Large single compilation-unit C programs (2006)

#13

I've been working on a project that auto generates c programs - sometimes up to 1.5m lines of code - in a single file (actually two files but the second is only 35 lines) Not open source but happy to share benchmarks if that would be useful.

Please share the benchmarks...

Re: Large single compilation-unit C programs (2006)

#14
post #13

I've been working on a project that auto generates c programs - sometimes up to 1.5m lines of code - in a single file (actually two files but the second is only 35 lines) Not open source but happy to share benchmarks if that would be useful.

Please share the benchmarks...

Will do - give me a few hours (and that's not the compilation times!).

Re: Large single compilation-unit C programs (2006)

#15

I've been working on a project that auto generates c programs - sometimes up to 1.5m lines of code - in a single file (actually two files but the second is only 35 lines) Not open source but happy to share benchmarks if that would be useful.

Too bad it's not open source, but will some of the generated programs be?

Also, would you mind comparing it to Csmith (https://embed.cs.utah.edu/csmith/)?

Re: Large single compilation-unit C programs (2006)

#16

Earlier quoted context omitted.

Well, according to C99, it should. Section "5.1.1.2 Translation phases" says (in phase 3): "Each comment is replaced by one space character." Edit: just checked and clang behaves just like gcc with -E. Maybe you didn't mean comments but preprocessor directives?

Clang, like GCC, has -C and -CC flags to preserve comments during preprocessing. However, these are really flags for the underlying preprocessor. Your parent might be thinking of some application of the Clang frontend that does not run preprocessing. For example, clang-format will probably not want to preprocess the code nor strip out comments.

You are correct, my bad.

Re: Large single compilation-unit C programs (2006)

#17
post #5
post #3

May be relevant to the discussion: SQLite is also compiled from a single, 220k LOC C file called "the amalgamation". https://www.sqlite.org/amalgamation.html

I also found this "amalgamate" script on GitHub, intended to allow creating such amalgamations from C/C++ projects: https://github.com/rindeal/Amalgamate Which seems interesting, however when I tried the FreeType example, there seemed to be some preprocessing issue, such that some function definitions are conditionally excluded even though they are called later. I didn't have the time to find out if this was an issue…

I'm not a C programmer, but I have heard of amalgamation, and I wonder why a standard workflow to create a single compilation unit from multiple source files isn't more straightforward.

Re: Large single compilation-unit C programs (2006)

#18
post #5

Earlier quoted context omitted.

I also found this "amalgamate" script on GitHub, intended to allow creating such amalgamations from C/C++ projects: https://github.com/rindeal/Amalgamate Which seems interesting, however when I tried the FreeType example, there seemed to be some preprocessing issue, such that some function definitions are conditionally excluded even though they are called later. I didn't have the time to find out if this was an issue…

I'm not a C programmer, but I have heard of amalgamation, and I wonder why a standard workflow to create a single compilation unit from multiple source files isn't more straightforward.

Because C is stuck in the dark ages.

Textual preprocessors are evil.

Re: Large single compilation-unit C programs (2006)

#19
post #5
post #3

May be relevant to the discussion: SQLite is also compiled from a single, 220k LOC C file called "the amalgamation". https://www.sqlite.org/amalgamation.html

I also found this "amalgamate" script on GitHub, intended to allow creating such amalgamations from C/C++ projects: https://github.com/rindeal/Amalgamate Which seems interesting, however when I tried the FreeType example, there seemed to be some preprocessing issue, such that some function definitions are conditionally excluded even though they are called later. I didn't have the time to find out if this was an issue…

That took a few minutes to make it work on newer macos.

Re: Large single compilation-unit C programs (2006)

#20

Earlier quoted context omitted.

The preprocessor doesn't remove comments and at least in clang, comments are parsed into the AST.

Well, according to C99, it should. Section "5.1.1.2 Translation phases" says (in phase 3): "Each comment is replaced by one space character." Edit: just checked and clang behaves just like gcc with -E. Maybe you didn't mean comments but preprocessor directives?

[deleted]
Post reply on HN