top | item 4644680

Ask HN: Interesting (small) bits of C or C++ code

10 points| malux85 | 13 years ago | reply

Hey everyone!

I'm looking for interesting bits of C or C++ code, smaller programs or functions. That I can read and learn from.

Not looking for hello world examples, more complex. An example of "Hey thats neat" would be donut.c (http://www.a1k0n.net/2011/07/20/donut-math.html)

Anybody else know of cool little gems like this?

6 comments

order
[+] quadfour|13 years ago|reply
there is a reddit dedicated to small snippets of code called tinycode, but it does not focus in any particular language. Github maybe your best option.
[+] thomasbk|13 years ago|reply
A little-known operator in C++, the "goes to"-operator:

int i=4;

while(i --> 0) { cout << i; }

[+] dysoco|13 years ago|reply
Actually that's just decrementing and comparing to 0: while((i--) > 0)
[+] athesyn|13 years ago|reply
Github.

I've found cool/interesting functions (and even one-liners) by browsing around randomly.