r/Cprog • u/clm100 • Feb 15 '15
r/Cprog • u/[deleted] • Apr 12 '16
Small, lesser known C compilers - a list
Every C compiler that is not gcc or clang and runs on either Linux, MacOSX or Windows is accepted. Please also give the supported versions of C. The project should at least attempt to accord to an existing standard.
8cc: A small, self-hosting C11 compiler.
tcc: The fastest known C99 compiler, by Bellard.
c: Attempt at a very elegant, small C11 compiler by Andrew Chambers.
scc: A C99 compiler by the suckless project.
fcc: Fedjmike's C11 Compiler.
pcc: pcc, the portable C99 compiler
lcc: lcc, a retargetable C99 compiler
ack: The Amsterdam Compiler Kit, originally written for Minix. C89.
neatcc: Sub-C89 compiler with the goals simplicity, usability and reliability. The manual.
nwcc: C89 compiler written by Nils Weller. Already able to compile applications like for example bash and lynx.
Suggested by /u/FUZxxl: kencc, and the Plan 9 compilers (although they don't run on Linux or MacOSX or Windows). I didn't find any official link for the sun C compiler.
Suggested by /u/systemsock: pellesc. A small IDE (compiler, assembler, macro assembler and a lot more) for Windows.
Suggested /u/wang_li: Oracle Solaris Studio
suggested by /u/staalmannen: openwatcom, "the only proper 16-bit compilers still alive".
Suggested by /u/skeeto: sdcc: a retargettable, ANSI C compiler, bcc: Bruce's ANSI C compiler
Suggested by /u/dmitrinove: vbcc, a "highly optimizing portable and retargetable ISO C compiler"
Other C compilers I did not consider worth noting.
Thanks for the submissions!
I will put them into the wiki and post a similar thread about implementations of the C standard library.
r/Cprog • u/malcolmi • Oct 11 '14
text | learning | language Do not trust random websites about C
ramblings.implicit.netr/Cprog • u/Jinren • Dec 26 '15
A simpler printf
Consider the following (assume suitable definitions for M_NARGS, M_FOR_EACH and panic, which are boilerplate easily found elsewhere):
void my_fprintf(FILE * stream, const char * format, int argc, const char * argv[static argc]) {
int next_str = 0;
for (const char * c = format; *c; ++ c) {
if (c[0] == '$' && c[1] == 'V') {
if (next_str >= argc) { panic(); }
for (const char * d = argv[next_str]; *d; ++ d) {
putc(*d, stream);
}
++ next_str;
++ c;
} else {
putc(*c, stream);
}
}
}
enum { MY_FPRINTF_BUF_SIZE = 32 };
#define my_fprintf(stream, format, ...) my_fprintf(stream, format, M_NARGS(__VA_ARGS__), \
(const char *[]){ M_FOR_EACH(MY_FPRINTF_FORMAT_ARG, __VA_ARGS__) })
#define MY_FPRINTF_FORMAT_ARG(A) _Generic((0, A), \
int: my_format_int, \
float: my_format_float, \
double: my_format_float, \
char: my_format_char, \
char*: my_format_string)(A, (char[MY_FPRINTF_BUF_SIZE]){0}),
const char * my_format_int(int a, char buf[static MY_FPRINTF_BUF_SIZE]) {
snprintf(buf, MY_FPRINTF_BUF_SIZE, "%d", a);
return buf;
}
const char * my_format_float(double a, char buf[static MY_FPRINTF_BUF_SIZE]) {
snprintf(buf, MY_FPRINTF_BUF_SIZE, "%f", a);
return buf;
}
const char * my_format_char(char a, char buf[static MY_FPRINTF_BUF_SIZE]) {
snprintf(buf, MY_FPRINTF_BUF_SIZE, "%c", a);
return buf;
}
const char * my_format_string(const char * a, char unused[]) {
(void)unused;
return a;
}
#define my_printf(...) my_fprintf(stdout, __VA_ARGS__)
int main(void) {
my_printf("Hello $V!\n", "world");
my_printf("There are $V arguments to this call. The remainder are $V, $V, $V, $V and $V.\n",
6, "foo", "bar", (char)'c', 'd', 4.75);
}(assume also a more complete/complex/correct core implementation in a real-world scenario)
In other words, between features added in C99 and C11, it's possible to design a printf-like function that doesn't need to care about type-specific format specifiers, or use va_list in the implementation:
C99 added
__VA_ARGS__and made it possible to implement theM_NARGS(count number of arguments) macro, which reduces the importance of theva_listbecause we can now pass fixed-length arrays and a generated array length (it also added checkable array length specifiers for function arguments, which are at least potentially useful for non-pointers). This is unfortunately of limited use for aprintf-like function because an array demands all elements have the same type. But...C11 added
_Generic, which gives us a way to convert all of the arguments in the variable list to a single type outside the function's body, prior to being added to the argument array. This eliminates the need for ava_listas the function no longer needs to accept variably-typed arguments at all.
In theory, I think this should have the potential to be safer (argument array is of a known size, stack doesn't risk being inspected, error is guaranteed catchable) and slightly more convenient (e.g. you could add a ${1} style syntax to grab substitutions multiple times). Whereas printf itself requires a compiler to go outside the language to analyse its correctness, which doesn't sit so well with me.
r/Cprog • u/schmidthuber • Jan 18 '15
text | code | systems Write a shell in C
r/Cprog • u/Aransentin • Mar 17 '16
The ISO C WG has started working on a new standard: C2X
open-std.orgr/Cprog • u/alecco • Nov 28 '14
text | code | systems How Not To Write a Signal Handler
741mhz.comr/Cprog • u/[deleted] • Aug 23 '15
C Programming Substance Guidelines AKA Everything You Need to Know to Write Good C Code AKA The StrongLink Programming Guidelines
r/Cprog • u/malcolmi • Mar 07 '15
text | systems What a C programmer should know about memory
r/Cprog • u/malcolmi • Oct 10 '14
text | humor The C Paradox: "I'm gonna live fast, die young, and leave a good-looking corpse" (2011)
dis.4chan.orgr/Cprog • u/malcolmi • Apr 09 '15
text | code | systems | virtualization Emulator 101 - a detailed, step-by-step guide to writing an Intel 8080 emulator
r/Cprog • u/benwaffle • Jan 13 '15
text | code | language Implementing smart pointers for the C programming language (x-post /r/programming)
r/Cprog • u/[deleted] • Dec 08 '14
text | tooling | debugging Valgrind is *NOT* a leak checker « Modern Maintainable Code
r/Cprog • u/malcolmi • Oct 15 '14
text | news musl 1.1.5 released with full C11 library support, including the C11 threading API
r/Cprog • u/malcolmi • Dec 05 '14
text | code | systems A quick tutorial on implementing and debugging `malloc`, `free`, `calloc`, and `realloc`
r/Cprog • u/stag1e • Oct 22 '17
Making Unwinding Functions in C Simple: Do Not be Afraid of Using Gotos
giedrius.blogr/Cprog • u/malcolmi • Nov 16 '14
code | library | language | algorithms Cello - higher level programming in C
libcello.orgr/Cprog • u/[deleted] • Apr 17 '16
sort.h - compile-time sorting library in a header
https://github.com/swenson/sort
"sort.h is an implementation a ton of sorting algorithms in C with a user-defined type that is defined at include time.
This means you don't have to pay the function call overhead of using standard library routine. This gives us the power of higher-level language generics.
In addition, you don't have to link in a library: the entirety of this sorting library is contained in the header files."
r/Cprog • u/shadows_on_the_wall • Jan 05 '16
A defense of C's null-terminated strings
utcc.utoronto.car/Cprog • u/malcolmi • Feb 22 '15
text | code | systems | networks Systems programming wiki by students and faculty at the University of Illinois at Urbana-Champaign
r/Cprog • u/malcolmi • Nov 22 '14