Questions tagged [c11]

C11 is a standard for the C programming language. It replaces the previous C99 standard. C11 added type-generic expressions, alignment support, static assertions, library support for multithreading and unicode as well as multiple other language and library fixes and additions.

Filter by
Sorted by
Tagged with
4 votes
3 answers
429 views

C11 zero copy lock-free triple buffer

The code is for a single producer, single consumer scenario, where the consumer only cares about the latest information shared by the producer. This is just a simple proof of concept created for linux....
mausys's user avatar
  • 49
3 votes
5 answers
161 views

Calculate a math sequence that converges

Thanks for taking the time to read this. I could use a few pointers. I have written much better code but wrote this as a quick test. There is obviously a major issue/s somewhere except for the ...
J123's user avatar
  • 33
-1 votes
1 answer
132 views

Brainfuck interpreter in C, looking for improvements on the looping functionality [closed]

I've just started to get into PL design and made a simple Brainfuck interpreter. Although it is functional, I don't feel too confident on the execution, particularly the implementation for loops, I ...
Iñaki Ulibarri's user avatar
2 votes
3 answers
1k views

Simplified print and input macros in C

For a program I'm writing, it requires a lot of printing and receiving user input. I've found it cumbersome to keep specifying the type strings in printf, and ...
Linny's user avatar
  • 9,989
3 votes
0 answers
81 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 ...
rng_help's user avatar
3 votes
1 answer
81 views

Basic Subnet Mask Calculator + A Little Extra

For my Networking class, we learned about subnetting and subnet masks. I decided to write a little "calculator" (a generous term) that when given n-many network ...
Carcigenicate's user avatar
5 votes
2 answers
1k views

Implementation of memset_s based on C11 standard

The following code attempts to implement memset_s() based on section K.3.7.4.1 of the ISO/IEC 9899:201x N1570 draft: ...
Tanveer Salim's user avatar
12 votes
1 answer
854 views

Function to print a double - exactly

Rarely is the exact value of a double needed to be printed and only its leading significant digits, after rounding, are needed. It is a curiosity to see the exact ...
chux - Reinstate Monica's user avatar
9 votes
5 answers
7k views

Convert UTF8 string to UTF32 string in C

I'm doing some recreational programming in C (after spending some time in C++, but professionally using only PHP/JavaScript). I wrote a UTF8 to UTF32 converter and just wanted to know if I made some ...
S22h's user avatar
  • 193
2 votes
0 answers
166 views

Lock-free statically allocated async-interrupt-safe multi-consumer double buffer

I have a single threaded embedded system with nested interrupts. A writer interrupt will periodically update some global data structure with data. Reader interrupts / calls from main thread will read ...
user80551's user avatar
  • 121
3 votes
1 answer
239 views

Stack allocator and C11's alignment features

I am trying to write a custom stack allocator for a game I am working on. To deal with memory alignment, I am using C11's stdalign.h header; however, since I do not ...
strNOcat's user avatar
  • 131
3 votes
2 answers
142 views

Simple command line option parser

As part of a project where I will be rewriting the most common GNU coreutils for practice purposes, I wrote a simple command line option parser in C. The parser works by categorizing ...
Ben Steffan's user avatar
  • 5,228
8 votes
2 answers
227 views

A dynamic string interface in C

So I've written up what the title says. Obviously, I'm looking for speed, safety and ease of use. To achieve the perfect ratio I've made some functions straight away crash if the input is wrong (in ...
DeiDei's user avatar
  • 551
4 votes
1 answer
181 views

IRC Client with TLS and SASL support

I wrote this little program to... I don't know. But it connects to IRC servers using OpenSSL and can login via SASL. The code needs refactoring, of that I'm certain, but I need some advice in that ...
Ezechiel's user avatar
  • 137
4 votes
0 answers
73 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 ...
Molly Stewart-Gallus's user avatar
5 votes
2 answers
68 views

Calculate maximum possible helpful flags for n days

This program is supposed to calculate the mathemathical maximum of helpful flags you can have on the nth day, starting with 0 helpful flags, using the StackExchange ...
Magisch's user avatar
  • 330
4 votes
2 answers
128 views

A dynamic memory resource with alignment support

Although C11 introduced aligned_alloc( alignment, size ), there is no support for aligned reallocation (AFAIK). The ...
user2296177's user avatar
  • 3,533
3 votes
1 answer
119 views

Generic variable-size array

As stated in the tags, I'm a beginner to C. This code implements a dynamic array (List in .NET, vector in C++, etc) for any ...
Kroltan's user avatar
  • 284
7 votes
2 answers
3k views

Simple OpenGL image viewer in C

I'm making an image viewer and before I continue development I want to make sure I haven't done anything bad. In particular, I was wondering if my error handling is sane. Most of the code is OpenGL/...
Ezechiel's user avatar
  • 137
4 votes
1 answer
343 views

A Generic Approach To Doubly Linked Lists

I've written a small implementation for doubly linked lists. While actually intended to be only used by me in subsequent projects, I wrote it as generically as possible. Maybe this'll be advantageous. ...
cadaniluk's user avatar
  • 187
1 vote
4 answers
155 views

Copy/remove characters "in place" without causing UB from strcpy

I am writing a portable library function, which is a generic "remove characters" function. Language standards used are C11 and MISRA-C:2012. TL;DR: it should either remove all occurrences of a ...
Lundin's user avatar
  • 4,495
5 votes
1 answer
696 views

Dining Philosophers using C11 threads

I wanted to try multithreading out in C, so I did Dining Philosophers using C11 threads with the approach of having one of the philosophers left-handed. Any suggestions? ...
Vikaton's user avatar
  • 153
3 votes
2 answers
144 views

Single reader - multiple writer waitable lock-free unreliably ordered stack

The main body of code is located here. In the code linted_error is a platform specific type for error codes. As well, as an optimization the code can use Linux ...
Molly Stewart-Gallus's user avatar
9 votes
2 answers
123 views

A closed exception system

I am working on yet another toy project that I named SGL (for "Standard Generic Library" since it mimics some features of C++'s STL as well as a few more utilities from the C++ standard library). ...
Morwenn's user avatar
  • 19.9k
9 votes
2 answers
247 views

Reasonable way to implement "safe" math operations using _Generic?

I've been thinking about a way to make it easier to safely use math operations with C's basic datatypes (e.g. using the CERT C coding standard). So far, I've come up with something like this: ...
acarlow's user avatar
  • 193
16 votes
2 answers
5k views

Template vector struct in C11

This one review will be a little bit tricky: I was trying to implement a template Vector struct in C11. Of course, templates don't really exist in C11, so I used a ...
Morwenn's user avatar
  • 19.9k