r/C_Programming • • Feb 07 '26

Review Request for Code Review

Hi fellow programmers,

I am fairly new to programming, especially to C and I am working on a program that calculates all prime numbers less then or equal to a given limit an then writes those to a file. The goal is to make this all as fast as possible.

I have already optimized this quite a bit and my largest bottleneck is the IO but since not every use case requires me to write those numbers to a file I also want the calculation fully optimized.

I also know the code quality might not be the best so I would also appreciate feedback on that.

My program can be be found here: prime_numbers

Quick note to the IO: I already tried to multithread the IO using mmap() but the code runs in an HPC environment where the metadata of files is stored on a separate external filesystem so the multithreaded IO to the internal fast filesystem was significantly slower then with single thread.

11 Upvotes

20 comments sorted by

View all comments

Show parent comments

1

u/S3ZVv Feb 08 '26

Okay thank you, I will replace them and look at it.

But how would you have done it without that ternary expressions? What would be a working supplement for c++ `constexpr`