Questions tagged [c]
C is a general-purpose computer programming language used for operating systems, games, and other high performance work and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the Unix operating system.
4,102 questions
3
votes
1
answer
420
views
Term only, arrow-only category foundations in C
I am learning to write an arrows-only, Term only foundations in C, because I noticed Lean4 has types and terms, so I thought maybe it would be nice to have term as the basic building block.
Please ...
3
votes
1
answer
714
views
"Frankenmallow" C code uses arc4 to choose flavors and coatings in arrays for mallow ideas, w/ switch cases, and countdown, functions: rngch ctdn
Is there any way to improve my spaghetti as a new C programmer? I'm both trying to make my program functional and nice, as well as easy to debug, and I've done a lot for this, can the codebase be ...
9
votes
2
answers
820
views
Arena Allocator in C
This is my first time doing any kind of serious coding in C. I watched a Youtube video on what an Arena Allocator should do and I tried my best to make an implementation for it.
As of now, we have the ...
7
votes
6
answers
768
views
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 (loop-free) to compute this number than computing a level and then going back?
...
8
votes
1
answer
106
views
Mandelbrot set visualizer using GTK4, Cairo and POSIX threads in C
I have recently implemented a Mandelbrot set visualizer, which I used to reacquaint myself with multithreading using pthreads.
I'm just wondering whether the way ...
5
votes
2
answers
362
views
BRESort - Bitwise Relationship Extraction - Intelligent Adaptive Sorting Engine for 32/64-bit & Floating-Point Data
I want to begin by sincerely thanking the community for the invaluable feedback on my previous BRESort byte-sorting research. Your insights about enums, named constants, loop optimizations, and test ...
7
votes
4
answers
675
views
My BRESort adaptive sorting engine in C
I've created BRESort - an adaptive sorting engine that dynamically selects
optimal algorithms based on data patterns. It achieves 3.6-4.2x speedup over stdlib qsort ...
5
votes
4
answers
780
views
Reservation app in C with linked list, BST, and CSV
This is a reservations app with linked lists for insertion and BST for search.
It uses CSV files for storage, recursion for printing
and handles memory allocation for variable growth.
I'm looking for ...
2
votes
2
answers
121
views
C Native Messaging host
Native Messaging host in C.
Documentations
Chrome Developers
MDN Web Docs
Microsoft Edge Developer documentation
Messaging between the app and JavaScript in a Safari web extension
Native messaging ...
3
votes
2
answers
387
views
Hashmap in C (with templates?)
I started implementing my own hashmap in C after taking inspiration from Git's hashmap API. As far as I know, the closest thing to templates in C are macros. I've seen that they are used in uthash or ...
4
votes
3
answers
231
views
Field Sorting , ANSI-C/K&R 2ED, Exercise 5-17 brainstorming
This program is an expansion of the sorting utility built in previous chapters of K&R's 2nd edition of ANSI-C Programming. It parses command-line arguments to determine which fields to sort by and ...
7
votes
4
answers
1k
views
Project Euler #909: L-Expressions I
I am trying to solve the 909th challenge of Project Euler. It is basically about replacing specific patterns in a string until no pattern is found. A given string like ...
2
votes
1
answer
140
views
ds (directory switcher): a *nix program for tagging directories with (short) tags and switching between them via tags
Repo
The complete program: GitHub repository
How it works
After you have cloned the above repository, change directory inside it and type make in order to compile ...
11
votes
4
answers
1k
views
A simple server-client application in C
I am reading "The Linux Programming Interface" by Michael Kerrisk. I'm studying about sockets, and I made a simple application using sockets on the unix domain.
I want to know if I'm using ...
4
votes
1
answer
111
views
Lock-free queues and stacks
I am currently working on implementing lock-free stacks and queues. So far, they seem to function properly in test programs, but I am unsure if there are any underlying issues or areas for improvement(...
14
votes
5
answers
2k
views
I implemented FFT in C
I wrote Cooley-Tukey's FFT algorithm in C. And I want to know how safe is this code? Is it just trash? How can I make it more memory safe?
...
6
votes
0
answers
184
views
Markdown parser library in C
For a side project, I needed a markdown parser and I decided to roll my own.
It is a SAX-style parser, i.o.w. you can hook into parser events on consumer side and do whatever you want with the content....
8
votes
1
answer
614
views
Shared-Memory Queue Implementation in C
Recently I am working on implementing a shared-memory based IPC message queue in C programming language on Linux system. A few design choices I've made include
The queue will have only 1 producer, ...
11
votes
2
answers
1k
views
Parsing HTTP headers in C
I'm new to C and just finished K&R. This is a code that I've written to parse headers of a HTTP request.
I want to know if my code:
Is safe? (after all this is C)
Does proper exit on failure? Are ...
10
votes
6
answers
2k
views
k-Nearest Neighbors algorithm in C
I've been learning C for a while, and I decided to make a simple kNN program. What can I do to improve the program?
Am I doing memory management right? Can the structure of the code be improved in ...
3
votes
0
answers
61
views
library variant during application startup
I wrote some PoC for load library with best optimization version during application startup. The goal for it check in the _init function code checking by cpuid ...
7
votes
4
answers
2k
views
Rot13 encryption with extra functionality using unix flags
I just wanted to check out options/unix flags and read from stdio through pipe. Is it any good? Where should I improve or use something else? Feedback would be much appreciated.
...
7
votes
7
answers
2k
views
LinkedList data structure in C
Is my logic good? Are variable names fitting? Are there any memory leaks? Am I doing anything dangerous (this is C after all)?
Please feel free to criticize the code. I want to know if I'm writing C ...
8
votes
5
answers
2k
views
C method to determine whether a byte array is homogeneous
I engineered myself into a situation where I wanted to check whether a region of memory consists of identical bytes. I wanted to at least try to avoid the obvious solution of an O(n) loop, but also ...
2
votes
1
answer
217
views
Attempt at a Different Variation of the strstr(...) Function
I decided to work on an idea I had to 'optimize' the classic C function strstr.
Most of the implementations I had seen that did not make use of advanced ...
5
votes
4
answers
677
views
Single Consumer Single Producer Wait-Free Zero-Copy Circular Message Queue
The title describes pretty well what the algorithm is for. It will be used for a realtime inter-process communication library that only uses shared memory for exchanging data. For realtime systems, it'...
4
votes
0
answers
93
views
16x16 integer matrix transpose using SSE2 intrinsics in C
I was inspired by this and this to make a C function that would take an array of 16 __m128i, treat it as a matrix of 16x16 ...
2
votes
0
answers
112
views
compile time, but Not inlined function in C and C++
We have a graphics library for the Ti84CE, which uses the 24bit eZ80. It has a 16bit 1555 screen, so we have a gfx_Darken function that will darken a 16bit 1555 ...
7
votes
2
answers
1k
views
Desperately seeking a hashing function
A recent CR exchange led me to dust off and adapt some code I'd written a few years ago. Long, long ago, when core meant ferro-magnetic memory cells, I spent an hour formulating a "simple" ...
5
votes
3
answers
1k
views
Arcane algorithm to find a keyword in a lookup table
This code is supposed to efficiently return the index+1 of a matching keyword from a lookup table of up to 31 keywords ...or 0 if the keyword is not found.
The line ...
4
votes
1
answer
512
views
Find a keyword in a lookup table
This code is supposed to efficiently return the index of a matching keyword from a lookup table or 0xF if the keyword is not found.
The line is a zero-terminated ...
2
votes
1
answer
121
views
Efficiently simulating a control sequence
I have a control problem that I am simulating in C. The premise is that I have some continuous-time signal s(t) and I am given some length-150 array ...
7
votes
3
answers
1k
views
Naive attempt at implementing a dictionary in C. Stack-based and O(n)
I am a C++ programmer trying to learn C.
Please critique my C code here. I am trying to make a small "hash table" that's \$O(n)\$ lookup. But, it is stack-based and so should be no slower ...
3
votes
2
answers
199
views
Numerical integration using Gauss and trapezoidal methods [closed]
I have written a code that performs numerical integrations—one using the Gauss method and the other using the trapezoidal method. For the Gauss method, I have five separate text files containing the ...
7
votes
1
answer
342
views
Robin Hood Hash Table
The following code comes from an intrusive container library I am working on in C23. So far, it works correctly due to extensive testing and sample programs I have written with it. I have implemented ...
6
votes
5
answers
2k
views
Quiz game in C V1.0
I made a quiz game in C. It is about answering questions as fast you can. At the end it say "Run successful of run failed in Apache.net Beans(false answer + seconds used ). Here is the codes:
<...
-4
votes
1
answer
393
views
int128 handling in C code, gcc / glibc / linux - follow up IV [closed]
[edit] Hint: a similar project for C++20 which - as far as I see - also manages bigger than 128-bit integers can be found at: Infinite precision integer in C++20 . [/edit]
I got lots of kind hints on ...
5
votes
2
answers
207
views
SDL3 Thread pool for fast cross-platform data parallelism
I'm working on a custom engine to make games with SDL3. I've spent the last few weeks trying to improve performance with multi-threading, which has culminated in this thread pool I'm calling "...
7
votes
5
answers
2k
views
Solving an easy LeetCode "Merge Strings Alternately"
I am a C++ dev trying to solve problems in C to practice it, specifically the LeetCode Merge Strings Alternately problem:
You are given two strings word1 and word2. Merge the strings by adding ...
3
votes
3
answers
617
views
int128 handling in c-code, gcc / glibc / linux - follow up III
I got helpful reviews for first steps in:
int128 handling in c-code, gcc / glibc / linux,
int128 handling in c-code, gcc / glibc / linux - follow up and
int128 handling in c-code, gcc / glibc / linux -...
3
votes
2
answers
906
views
int128 handling in c-code, gcc / glibc / linux - follow up II
I got very nice reviews for an attempt to produce read and print
routines for 128-bit integer datatypes in:
int128 handling in c-code, gcc / glibc / linux and:
int128 handling in c-code, gcc / glibc / ...
5
votes
2
answers
415
views
int128 handling in c-code, gcc / glibc / linux - follow up
I had a draft for int128 handling reviewed there:
int128 handling in c-code, gcc / glibc / linux
I changed a lot according to the hints there, while leaving in, e.g.,
a trailing space on each line, ...
7
votes
5
answers
2k
views
int128 handling in c-code, gcc / glibc / linux
[edit] Hint: a similar project for C++20 which - as far as I see - also manages bigger than 128-bit integers can be found at: Infinite precision integer in C++20 . [/edit]
I work on some performance ...
11
votes
6
answers
1k
views
fsize: A Command-Line Tool for Checking File Sizes
I have created a cross-platform CLI tool to quickly retrieve file size and present it to the user in different units of data. The whole program is written in C and for Windows Win32 API is used to ...
9
votes
4
answers
2k
views
"Weird Algorithm" (Collatz) from CSES Problem Set
I had to solve the following problem:
Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by ...
8
votes
2
answers
282
views
Leetcode 93: Restore IP Addresses (C version)
This is posted in response to this request made in a discussion of my "C-ish" answer to a recent Code Review question regarding a Python solution to a Leetcode challenge. It was reported ...
6
votes
2
answers
185
views
Simple paint program
This is the beginning of a simple X11/Xlib paint program. I got most of this code from an online source and started to modify it. But since I'm new to X11, I thought I'd ask before I add on to bad ...
6
votes
2
answers
225
views
Collatz - another view
Most coders have, at one time or another, dabbled with "The Collatz Conjecture"; a pair of simple math operations that seem to always find their way cycling through ...
7
votes
2
answers
664
views
C vs. C++: comparing function pointer tables and switch-case for multiple types support
I have some API code that I need to rewrite. The original API is written in C++ and relies heavily on templates and modern C++ features like std::is_same_v. The ...
6
votes
1
answer
535
views
Is this a correct implementation of atomic reference counting in C?
Giving the following constraints, is the optimization in this code correct?
before an object is transfered to another thread, its reference count is incremented and ...