HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
glouw
ctl
C2020–2025
glouw / ctl

ctl

The C Template Library

8Distinct people
22Mentions
1Explicit recommenders
1.4KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

The C Template Library

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

CTL. https://github.com/glouw/ctl It's functionally blackbox compatible with the STL for the major containers. Unless you're writing heap spaced firmware where C++ with an STL…

glouwbug used a recommendation phrase. One indexed comment matches. This is a phrase match, not a verdict.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 8–Nov 15 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/15/2026, 4:00:59 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year22 dated mentions

Observed mentions: 2020-10-25 21:39:42 UTC to 2025-06-27 10:16:58 UTC.

02468102020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 8 mentions; 1 submissions, 7 comments20202021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 10 mentions; 0 submissions, 10 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments20222023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2025

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC817
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC10010
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC202
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC000
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC000
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC202

What Hacker News says

8 sources
The performance of sort being exactly the same as the C++ implementation looked a bit suspicious to me at first. Notable that in the C++ performance test a function pointer is passed to std::sort in a similar way how the C library is used [1]. This is probably a good way to check that the C library doesn't do worse in this case, but it's notable that C++ has potentially faster ways to do the sorting: 1. Pass a function object (even a lambda that just wraps "compare") 2. Don't pass a comparison at all for the "vector<int>" case, as the default works there. Both of these methods have better chances for inlining the comparison within the sort implementation. For the function pointer case it would require constant propagation and possibly "cloning" to do the same, which is less likely for a complicated algorithm like sort. [1] https://github.
Read the rest
com/glouw/ctl/blob/09f5e0a89d3fc621aff94290c4... edit: I wonder how ctl's vector sort compares to qsort, I expect it to be faster.
In C Template Library
I backported a handful of C++ STL containers to ISO C99 to exemplify that a subset of C++, namely C with Templates, is a highly usable type-safe feature within the realm of ISO C99. Included are a couple examples, like a JSON parser and a simple 6502 compiler. I have also written a small wiki, that showcases how to use the included containers: https://github.com/glouw/ctl/wiki
In C Template Library
If anyone is interested, I'm in the process of back porting the STL to C99: https://github.com/glouw/ctl The gist of its workings is including a header and defining its type: #define T int #include <vec.h> #define T float #include <lst.h> #define T str #include <deq.h> For more complex types, copy, free, and default constructors are supported, given they're defined before the inclusion of the container: typedef struct { void* data; } blob; blob blob_copy(blob* self) { ... } // Copy constructor void blob_free(blob* self) { ... } // Destructor blob blob_init(void* data) { ... } // Constructor blob blob_init_default(void) { ... } // Default constructor #define T blob #include <vec.h> int main(void) { vec_blob blobs = vec_blob_init(); vec_bloc_push_back(&blobs,
Read the rest
blob_init(...)); // Invokes constructor, element 0, passed by value vec_blob_resize(&blobs, 42); // Invokes default constructor for elements 1-42. vec_blob copy = vec_blob_copy(&blobs); // Invokes copy constructor for elements 0-42. vec_blob_free(&blobs); // Invokes destructor for elements 0-42. vec_blob_free(&copy); } The motivation for starting this project was to provide C++ like functionality to C, but provide hugely reduced build times.
In What's Wrong with C++ Templates? (2003)

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.