Skip to main content

New answers tagged

2 votes

K&R excercise 1-21 Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing

The "ternary expression" You've used the ternary expression as a replacement for a conditional statement in the following. ...
Chris's user avatar
  • 6,126
2 votes

Inserting into a linked list

If we're assuming that head is not NULL, so let's split up the responsibilities: writing a separate function that finds the tail ...
Chris's user avatar
  • 6,126
2 votes

Binary Search Tree implementation in C [1]

Style You mix braces and not using braces freely throughout your code. While this works, it leaves open the possibility of adding to branches of conditionals or to loops and forgetting to add braces, ...
Chris's user avatar
  • 6,126
3 votes

Max-heap implementation in C

It strikes me that there is an opportunity for some of your functions to be very straightforward preprocessor macros. ...
Chris's user avatar
  • 6,126
8 votes
Accepted

Term only, arrow-only category foundations in C

General Observations Possible bug, in the current implementation the dom and cod Term pointers are being assigned the value of ...
pacmaninbw's user avatar
  • 26.2k
2 votes

Schedule using binary tree in C

Indentation More than a single space for indentation makes code much easier to read. Four spaces is a very common convention for C. Nested conditionals Let's consider one function, with improved ...
Chris's user avatar
  • 6,126
6 votes

Arena Allocator in C

Poor naming Based on its name and type and type alias, I expect Arena.buffer to be a pointer to the starting address of the arena from which memory is being ...
John Bollinger's user avatar
1 vote

Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number

Firstly, there's absolutely no comments for the reader to understand the purpose of this calculation, i.e. what it might be used for. The name getsize() isn't much ...
Toby Speight's user avatar
  • 88.7k
8 votes
Accepted

"Frankenmallow" C code uses arc4 to choose flavors and coatings in arrays for mallow ideas, w/ switch cases, and countdown, functions: rngch ctdn

The formatting is really really odd. I see a lot of extraneous newlines, weird indentation, and brace style. Further, having holdreturn declared before it's ...
Chris's user avatar
  • 6,126
7 votes
Accepted

Arena Allocator in C

char pointer typedef char* Arena_ptr; That seems weird. I mean, it's your Public API, you get to define it however you want, signed char or unsigned or whatever. ...
J_H's user avatar
  • 43.3k
-2 votes

Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number

You want ...
Eric Towers's user avatar
4 votes

Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number

As chux said: Perhaps more research will lead to a no test approach. I've found this solution, which is indeed C++ instead of C but let's look past that for now: ...
user555045's user avatar
  • 12.6k
2 votes

Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number

For fun, consider a tree of depth log2(X_MAX). Is there a more direct way (loop-free) to compute this number than computing a level and then going back? A simple binary decision tree with 4 compares....
9 votes
Accepted

Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number

is there a more direct way? Look up table With 32-bit int, level is so limited in range as ...
chux's user avatar
  • 36.5k
2 votes

Computing the smallest number of the form floor(8^N / 7) that is greater or equal to a number

0x49249249 consider giving it a name - approximation of the multiplicative inverse of 7 mod the power of 2 that is the least multiple of 3 no less than the number ...
4 votes

K&R Exercise 5-10. reverse Polish calculator

Return values Several of your functions print error messages. While it's fantastic that you correctly print these messages to stderr instead of ...
Chris's user avatar
  • 6,126

Top 50 recent answers are included