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.

125 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
11
votes
0answers
246 views

Code to fill PE import address table

I wrote a program to test AV engines against encryption. When it runs, it will compute some key, decrypt an executable it has in its data section and copy it to the locations where the executable ...
8
votes
0answers
377 views

Red-black tree appears to be slower than std::multimap

I've written a red-black tree in C as an exercise. The tree works and it is not bad, but it is about 10% slower than std::multimap from libstdc++ which I'm ...
7
votes
0answers
140 views

Engineering an even faster qsort

I understand that C++ STL template sort runs faster than qsort in C because ...
7
votes
0answers
107 views

Error handling function (Win32/C)

I have written the following function to be a general "error logging" solution for my Windows API projects. Basically, given a Windows system error code (a la ...
6
votes
0answers
103 views

Console arkanoid in C

On an Internet forum a person came with their homework, to write Arkanoid in a console - it seemed they wanted someone to do their homework for them so I did not respond. However, I found the task ...
6
votes
0answers
402 views

C - fully threaded binary search trees

For learning purposes, I've decided to implement several classic data structures, starting with binary search trees. The entire code can be seen here, in a frozen branch ...
6
votes
0answers
156 views

Bidirectional bijective hash map in C

I have this bidirectional hash map in C for dealing with bijective maps. Each key mapping consists of a primary key and a secondary key, and I can ask the data structure to give me a secondary key ...
6
votes
0answers
130 views

Positioning a file pointer with MPI I/O

This toy code uses MPI I/O to read from a binary file. It goes through reading: an ASCII header the first 10 doubles from an array of 100 ...
6
votes
0answers
516 views

Gauss-Seidel+SOR

I am learning OpenMP+MPI hybrid programming. As an example I have chosen Gauss-Seidel+SOR. My implementation uses MPI_THREAD_FUNNELED style hybrid programming, ...
5
votes
0answers
65 views

C clone of Hackertyper.net

This is a simple C clone of the website hackertyper.net. The code can be found on Github and is reproduced below: Makefile ...
5
votes
0answers
529 views

Linux GPIO rotary encoder as volume control

I've written a kernel module (tested on Raspberry Pi) to use a rotary encoder as a volume control. The Linux source tree already contains a driver for rotary encoders so I've just piggybacked off of ...
5
votes
0answers
7k views

Implementation of Single Layer Perceptron Learning Algorithm in C

I have implemented a working version of perceptron learning algorithm in C. Right now, it only works on single layer perceptrons and only takes two inputs. I plan on making it work with more than two ...
5
votes
0answers
64 views

Yet another quicksort

Code review my quicksort! It isn't supposed to be superfast or anything and doesn't basecase out to insertion sort or anything. It's optimized for clarity and only sorts arrays of pointers. ...
5
votes
0answers
287 views

Cache conscious SIMD matrix multiply of unsigned integers

The goal of the code review by order of importance (i.e. What I hope to hear from you): I've verified correctness using a straightforward matrix multiply function though I am open to those who want ...
5
votes
0answers
825 views

Reusing curl easy handles in C

In a C project I want to reuse curl easy handles. The flow of program is like: Client --> C Application --> Call URL1, do something, Call URL2, do something, Call URL3... In short, for each client ...
5
votes
0answers
39 views

Variation of the internal PHP hashtable

I'm working on a PHP extension in an attempt to learn some C. I've implemented a variation of the internal PHP hashtable, which uses a lookup table and a separate bucket table. The lookup table simply ...
4
votes
0answers
45 views

Basic snake game in C

I wanted to learn C and Win32 so I thought the best way to start would be to create a simple game to get familiar with the language, so I made Snake. The games works perfectly except for sometimes ...
4
votes
0answers
70 views

3D Direct Convolution Implementation in C

For my project, I've written a naive C implementation of Direct3D convolution with periodic padding on the input. Unfortunately, since I'm new to C, the performance isn't so good. By convention, all ...
4
votes
0answers
62 views

C program to sort files based on information within

I have written a C program to sort files (on Windows) into dynamically created subfolders based on information found in their data headers. I am a newb at C, especially memory management. The code ...
4
votes
0answers
94 views

Generic Macro Generated Interval Heap in C

When I saw this amazing data structure I couldn't stop myself from trying it! I first sought resources such as this and an article about it here. It basically works as a Max-Heap and a Min-Heap at the ...
4
votes
0answers
103 views

Memory managment for RPC code in C

My team has been given care of an old embedded C project. Its main part is a security critical RPC API and I'm trying to create a new design of its internal interfaces to make it more robust against ...
4
votes
0answers
148 views

Fast Hardy-Weinberg equilibrium simulation

I was very bored over one of my breaks this year, so I built a Hardy-Weinberg equilibrium simulator for two unrelated alleles of the same gene. Hardy-Weinberg equilibrium is when there is no evolution,...
4
votes
0answers
79 views

General Purpose C Dictionary

I'm trying to create a general purpose C dictionary (as an opaque data type) capable of dynamically allocating basic types (ints, floats, strings and longs) as well as accepting void pointers to ...
4
votes
0answers
248 views

Fast ray/triangle intersection code in C

I wonder if someone is familiar with ray/triangle intersection algorithms and can help me optimize them? Here are my implementations of two ray/triangle intersection algorithms in C. The first is the ...
4
votes
0answers
45 views

Texplode KotH controller

I am creating a KotH (King of the Hill) challenge for Programming Puzzles and Code Golf. Other site users will write programs that play Texplode (a version of this game on a square grid). The program ...
4
votes
0answers
305 views

Time Limit Exceeded with shortest path algorithm

The problem: SHPATH You are given a list of cities. Each direct connection between two cities has its transportation cost (an integer bigger than 0). The goal is to find the paths of minimum cost ...
3
votes
0answers
37 views

Linear probing 16 hashmap elements in parallel using SIMD instrinsics

For my hashmap implementation, I'm caching hashes for each map element in an array of length NBUCKETS, where each element corresponds to an element in the hashmap. ...
3
votes
0answers
34 views

Binary PATRICiA Prefix Trie

I was wondering if we could speed-up lookup in a hash table of strings by only storing the difference between them, like HAMT. Taking this idea to it's end, I ended up with a binary PATRICiA prefix-...
3
votes
0answers
48 views

Async generation of large buffers of random numbers on the GPU

I would like to obtain some feedback on a simple code I wrote to implement an easy and hopefully fast way to generate a large number of floats with CURAND and use them one at a time. This is achieved ...
3
votes
0answers
104 views

Transfer an array of unknown size from C to Python using Ctypes

I am new to Ctypes. I am writing a piece of code that brings an array of unknown size from C to Python using Ctypes. Unknown size here mean that Python initially doesn't know the size of the array. C ...
3
votes
0answers
93 views

Emulating a C++ enum class C++ in C

I am trying to emulate a C++ enum class in C and the code works as I expect. I used this code as indicated on Stack Overflow. ...
3
votes
0answers
116 views

Generic Makefile for C projects

I'm trying to create a generic Makefile that will work with the following directory structure: Project Directory Makefile main.c source file source directory Source files include directory Header ...
3
votes
0answers
118 views

Taskbar for X11 using Athena widgets

I am developing a simple taskbar for X11 using the Athena widgets. The current code is very limited: it assumes an EWMH-compliant window manager and only adds the initially running windows to the ...
3
votes
0answers
247 views

K&R Exercise 1-13. Printing histogram of word lengths (vertical variant)

I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it. How does the following solution look to you? Note that, for the sake of exercise, I don't want to use ...
3
votes
0answers
68 views

Library for managing CLI flags

I'm pretty new to C, started learning it less than a month ago, the only language I had previous experience was Javascript. Anyways, I wrote a library for dealing with CLI flags. It's not a serious ...
3
votes
0answers
84 views

Print a list of disk blocks used by file(s) - Linux

This code takes a list of filenames as arguments or from stdin (or from a provided file) and dumps a list of disk blocks used by those files. An attempt is made to use the linux ...
3
votes
0answers
259 views

Eliminating chain rules from context-free grammars

I'm writing a small C program for elimination of chain rules from a context-free grammar. My idea is to rewrite the rules of the grammar in a specific useful order: making groups of productions that ...
3
votes
0answers
3k views

Simple Neural Network in C

A neural network is a structure of connections and nodes that takes input and generates an output. It can be "taught"(adjusting weights and biases of connections) from a teacher data set ...
3
votes
0answers
552 views

Complex multiplication and integration with CUDA

I want to perform multiplication on two vectors and integrate it in a vector called acc_y. The acc_y variable will update over ...
3
votes
0answers
1k views

A Thread-Safe FIFO in C99

I started a little weekend project to try and learn how to multithread with pure C99 and POSIX threads. The project is composed of three threads, input, processing, and output, which communicate with ...
3
votes
0answers
93 views

Minimum number of basic operations to convert str1 into str2

I am to convert a given string into another using only three basic operations, that is by deleting, inserting or replacing a character. Changes can only be made to string 1 and it is given that the ...
3
votes
0answers
55 views

Find spanning tree with maximum edges with the same weight

For my university assignment I need to come up with an algorithm to find a spanning tree with maximum number of edges with same weight. I received an algorithm suggestion in this Stack Overflow answer....
3
votes
0answers
6k views

OpenSSL Client/Server

I have recently begun to dabble with OpenSSL to provide TLS encryption to TCP socket communication. Through documentation and heavy reference on example code I have come up with the following code (...
3
votes
0answers
492 views

Attempt at multithreaded memory allocator

I'm trying to learn C and memory management, therefore as an exercise I've written a memory allocator. I've taken the best fit algorithm and added multithreading with locks. I'm a beginner with ...
3
votes
0answers
148 views

Random number generation

I'm trying to port some MonteCarlo code to CUDA (this is my first CUDA experience). The CPU code often calls a function which generates a random number: ...
3
votes
0answers
322 views

Simple virtual machine prototype for Lisp-style languages

I found a post I made here an year ago (Compiler for a minimal LISP dialect to run on the Java Virtual Machine) and got interested on this subject again. This time I decided to implement the ...
3
votes
0answers
49 views

Fast lock implementation using pipes only

For fun I wanted to create a lock implementation that was about as fast as one using futexes but that used used pipes instead and that queues waiters in user space instead of in-kernel. For the queue ...
3
votes
0answers
1k views

Mutex implementation without built-ins

I want to implement simplest mutex without built-in functions or the <pthread.h> module. ...
3
votes
0answers
270 views

Linux performance using multi-threads (vs one thread) and ssh message

My server receives requests in one thread and responds in another. I am using thread pools of pthread-s for both receiving and sending. The performance is not that bad, however... When I am doing the ...
3
votes
0answers
658 views

Rust-like “Result” in C - nicer error handling

There are frequently things I miss when using C; one of them is a nice error-handling (exception-like) system. After trying Rust, I realized I could implement something similar in C itself. So here's ...