10
votes
int128 handling in c-code, gcc / glibc / linux
Avoid naked magic numbers
Why 45 in char str[ 45 ];?
Instead
...
9
votes
Accepted
Integer to string via gcc converter
minus sign
void print_integer(int i_val)
You accept negative quantities, but there's
no logic for outputting a minus sign.
Consider making the parameter unsigned.
...
8
votes
Integer to string converter - gcc builtins only
Make isBigEndian() constexpr
If you can use C++20, then I'd just use std::endian to detect ...
7
votes
int128 handling in c-code, gcc / glibc / linux
Trailing whitespace on lines
Please remove the trailing space at the end of each line before the newline. Some code editors will automatically do this for you.
Unindent global variables
...
6
votes
Safer & simpler allocation functions and macros
Portability
While #pragma once is widely supported it is not part of the C programming standard. To make this library more portable, use include guards such as ...
6
votes
128-bit integer type in GCC/Clang
Consider the future when uint128_t is standard and available
You don't want your code to stomp on standard names, yet not require much code change.
Rather than <...
6
votes
Accepted
Consolidating GNU C's and C23's attributes
For any attribute that has either a standard version or a GCC/Clang extension, the separate #if clauses need to be #if/...
5
votes
4 different implementations of modulo with fully defined behavior
The code may be free of undefined behavior, but it relies on implementation-defined behavior because of the exit(-1). Read its definition in the C standard, not in ...
5
votes
Accepted
4 different implementations of modulo with fully defined behavior
Is there an error somewhere, something that i missed? Is there an error somewhere, something that i missed?
Certainly have most of main street covered.
...
5
votes
Can you please give feedback on my C++ Code?
Don't optimize prematurely
This Code uses the cstdio include for good performance
If you write C++ code, it is better to use the C++ way of doing things. While ...
5
votes
Accepted
Safer & simpler allocation functions and macros
Use Doxygen to document your code
It's already mentioned by others, but you have a lot of comments. It's good to document all the functions, but you are not using a standard code documentation ...
5
votes
Accepted
Efficiently read a file into a (C) string using POSIX APIs
This is a good project, one that could be very useful in practice. I’ve had two or three C++ blogs over the years, and every time I spin up a new one, I include an updated version of a very old post I ...
5
votes
Clang preprocessor concatenates an extra space vs. gcc - standard C99
I think this is beyond the jurisdiction of the C standard. See https://stackoverflow.com/questions/37796947/spaces-inserted-by-the-c-preprocessor. All the standard says on the topic is a footnote:
...
5
votes
Macro for counting number of elements in an array
We need to protect a when it's an expression - we've put parens around a[0] where we should have put them around ...
5
votes
Register "%b" conversion specifier
EDIT: I also fixed a typo: main should be int main(void)!
After fixing the bugs @chux found, there was still another bug:
This ...
5
votes
int128 handling in c-code, gcc / glibc / linux
I have some comments about the comments in your code.
Boilerpate
I would prefer not to see the boilerplate copyright comments at the top
of the file, having to scroll past a half of a screen to get to ...
4
votes
Accepted
Register "%b" conversion specifier
zero
min_len is calculated as 0 when val == 0. I'd expect min_len to be 1.
Casual ...
4
votes
Accepted
Bash script - compile and run c++ code for coding competitions
#!/bin/bash
I don't see why you're using Bash for this - there should be no problem using standard POSIX shell.
...
4
votes
C++ Template to implement the Factory Pattern
Seems pretty reasonable. I mean, I definitely wouldn't put this in production code because it relies on parsing a class name out of __PRETTY_FUNCTION__, and that's ...
3
votes
Accepted
Reference-counted smart pointer in C
Tolerate NULL during clean-up
As free(NULL) is OK, consider a NULL test for clean-up
...
3
votes
4 different implementations of modulo with fully defined behavior
Is there an error somewhere, ... Like a set of inputs that don't give the right result.
Code lacks basic tests to answer that.
Sample test harness. (It lacks % 0 ...
3
votes
A little C++ program to have timed rounds for a game
Make use of the do/while loop (instead of a while loop) where you can. Both ...
3
votes
A little C++ program to have timed rounds for a game
First, it's really not too bad for a beginner, there are functions with local variables and the function names are descriptive. I'm impressed with the fact that all ...
3
votes
Encapsulating snprintf to simplify usage: sbprintf & swnprintf
Welcome to the world of modern C++!
The OP has stated that "I don't think you need to write code that a C programmer couldn't understand to say that a program is C++." That's partially right — ...
3
votes
Accepted
Encapsulating snprintf to simplify usage: sbprintf & swnprintf
<cstddef> defines std::ptrdiff_t - the implementation is allowed to also define it in the global namespace, but it's not ...
3
votes
Encapsulating snprintf to avoid repetition of sizeof
No need to resort to non-portable GNU C extensions:
1. Replacement for GNU C's __builtin_types_compatible_p():
The intent I believe is to differentiate between ...
3
votes
Encapsulating snprintf to avoid repetition of sizeof
Pedantically, if (snprintf(buff, sizeof(buff), format, ...) >= SSIZEOF(buff)) goto err; is an insufficient test. Test for ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
gcc × 26c × 15
c++ × 10
formatting × 3
c++17 × 3
integer × 3
memory-management × 2
assembly × 2
posix × 2
macros × 2
makefile × 2
c-preprocessor × 2
performance × 1
game × 1
c++11 × 1
bash × 1
linux × 1
template × 1
io × 1
pointers × 1
converting × 1
statistics × 1
windows × 1
bitwise × 1
timer × 1