11 votes

An Arena/Bump Allocator in C

Pointers returned by the allocator are not stable Because you are using realloc for growing the heap, each call to arena_alloc will potentially invalidate all of ...
ComicSansMS's user avatar
10 votes
Accepted

A String View Library in C

Only include the header files that are required: #include <stdbool.h> #include <stddef.h> #include <stdio.h> It is useless to include both ...
Harith's user avatar
  • 5,551
8 votes
Accepted

An Arena/Bump Allocator in C

General The code is nicely formatted, and the use of comments judicious. Thanks! Tests? There is a distinct lack of tests. You do have a "brush" test, but it's quite insufficient in "...
Matthieu M.'s user avatar
  • 5,137
7 votes

Shunting yard calculator in C

while (1) { fgets(expr, 200, stdin); ... } What happens if fgets() fail? You are ignoring its return value. ...
Harith's user avatar
  • 5,551
6 votes
Accepted

This is a simple stopwatch cli application with a few options

Check the return value of library functions From the man page: signal() returns the previous value of the signal handler. On failure, it returns SIG_ERR, and errno is set to indicate the error. ...
Harith's user avatar
  • 5,551
6 votes
Accepted

Shunting yard calculator in C

Expanding on the idea of an array for the stack, the Node type wouldn't need to hold pointers and you wouldn't have to allocate a ...
TrayMan's user avatar
  • 288
6 votes
Accepted

Command-line parser that takes a command in C

odd semantics I don't understand this: static int is_option(const char *str) { return str[0] == '-'; } That is, if we try ...
J_H's user avatar
  • 24.7k
6 votes

An Arena/Bump Allocator in C

Memory Alignment Your implementation returns unaligned memory. On some architectures, allocating a char followed by an int, and ...
Davislor's user avatar
  • 7,371
5 votes

Binary tree deepcopy using the Morris traversal in C

single responsibility I need to perform a deep copy of a binary tree using the Morris traversal. Ok, maybe you. I confess it's not obvious to me why that is. Consider making the underlying binary ...
J_H's user avatar
  • 24.7k
4 votes

Binary tree deepcopy using the Morris traversal in C

tNode* node = (tNode *)malloc(sizeof(tNode)); In ancient times, malloc() used to return a ...
Harith's user avatar
  • 5,551
4 votes
Accepted

Literate Programming in C

I'm going to ignore the larger questions about the history of Literate Programming and just address the issues behind "a program to delete commentary but preserve code blocks set off between ...
Jonathan Leffler's user avatar
3 votes

Shunting yard calculator in C

double math? .number is a long double. I'd expect ...
chux - Reinstate Monica's user avatar
3 votes

Sort an array of strings using bubble sort

Style It is more readable to include spaces around binary operators such as the = assignment operator or comparison operators. ...
CPlus's user avatar
  • 928
3 votes

A String View Library in C

The accepted answer has done a fine job of reviewing the posted code. This answer will focus on the macros in this code. In summary: the OP code should remove the ...
ad absurdum's user avatar
3 votes

This is a simple stopwatch cli application with a few options

This looks silly at first: #define ONE_MILLION_NSEC 1000000 #define ONE_BILLION_NSEC 1000000000 But considering that you cannot yet write 1'000'000 in C, this will ...
Cris Luengo's user avatar
  • 5,573
3 votes

An Arena/Bump Allocator in C (Follow-up)

Passing arena to arena_new Instead of allocated arena on the heap during ...
Rish's user avatar
  • 2,091
2 votes

An Arena/Bump Allocator in C

debug The contract between caller and library goes two ways. Library promises to deliver a unique pointer to memory of proper size N. Caller promises to color within the lines, from 0 .. N-1, not ...
J_H's user avatar
  • 24.7k
2 votes

C99 - Lexer for the Monkey Programming Language from the book "Writing An Interpreter In Go"

Here's a few suggestions that are not specific to the Monkey language: Treat input as a stream To read the characters from the input, you should only use ...
TrayMan's user avatar
  • 288
2 votes
Accepted

C - Pattern To Initialize Values From Saved Data -- If It Exists

Are self-test values unique enough? It's tempting to look at the self-test values of a small number of MPUs, and from seeing that they are all different, conclude that they are therefore unique. But ...
G. Sliepen's user avatar
  • 55.4k
2 votes
Accepted

Benchmarking putchar_many vs puts Performance for the Same Byte

If you really are trying to output one character n times, and not n distinct characters, I would make putchar_many take the count and the char only. And then charge the allocation/free time to the ...
David G.'s user avatar
  • 1,333

Only top scored, non community-wiki answers of a minimum length are eligible