Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"05-31-11 - STB style code"

8 Comments -

1 – 8 of 8
Blogger Joel Bernstein said...

You could do it SQLite-style, where you structure your code however you like, and then a script jams it all together into one big amalgamation.

They actually claim it improves performance on certain compilers that won't do cross-file optimizations.

June 2, 2011 at 11:12 AM

Blogger cbloom said...

Yeah, that winds up being what I do by hand - I write the code in full library style, and then to make an STB version I go and copy-paste out all the dependencies I need.

I could actually probably automate that without hand-writing scripts. You just need a mini compiler to go and find everything you depended on and copy it into one file.

One evil way to do it would be for me to just compile my code into OBJ's and then run a disassembler and ASM to C converter to make really nasty plain C versions.

June 2, 2011 at 11:17 AM

Blogger Arseny Kapoulkine said...

You'll just need a quick'n'dirty preprocessor - really a #include handler that does not look at other preprocessing directives and skips #include <> (system includes). That's easy to write and should work in almost all cases.

June 2, 2011 at 1:49 PM

Blogger cbloom said...

"You'll just need a quick'n'dirty preprocessor"

Well, not exactly. I want it to strip away the things that I don't use.

eg. if I #include cblib/Base.h just to get my definition of "uint8" I don't want the whole of Base.h to get splatted in, just that one line.

It would be a pretty nice utility to have though. Given a C file make a version which is stand-alone. Maybe it's worth spending some time to write that.

And actually the same code could be used to generate my own Browse Info, since the core thing needed is a "find definition" function.

June 2, 2011 at 2:18 PM

Blogger Cyan said...

This SQLite amalgation process just looks the right way to do it. I really like the philosophy behind that construction.
Is this "amalgation utility" strictly internal to the SQLite team ?

June 2, 2011 at 3:14 PM

Blogger cbloom said...

The SQLite amalgamation just takes all their files and cats them together.

They have a TCL script that you can download which just copies all the source code into the amalg file, and when it sees a #include it puts the text of the #include inline, but only the first time.

It's a decent easy way to "STB-ify" an entire library, but it doesn't do what I really want, which is to extract a piece of my big monolithic home codebase.

June 2, 2011 at 5:01 PM

Blogger johnb said...

I have this same problem, and I so often end up just copying a bunch of code from one project to the next, and usually having to fix up #includes and what-not as well. It's horrible. It's because C and C++ have no good module system, no standard build system and no standard package management system.

Overall this means the overhead of creating an independently distributable module in C or C++ is just horribly, horribly high.

Haskell has Hackage, perl has CPAN, ruby has... I dunno, gems or something. Python has PyPI. Most TeX distributions have some massive and standard repository you can grab things from.

We need a good C/C++ package management tool that's cross-platform and integrates with all common build systems and version control systems.

June 3, 2011 at 12:52 AM

Blogger cbloom said...

Well I just wrote an "amalgamate" but it doesn't actually work on any kind of large code base.

I'll post my code anyway and explain why it don't work.

June 3, 2011 at 8:16 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.