Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
3 votes
1 answer
712 views

Cross platform raw input handling in C/C++ for Linux and Windows

For some of my terminal videogames I need to accept input in raw mode, which can be done in Windows by using the nonstandard function getch coming from the header <...
FLAK-ZOSO's user avatar
  • 183
3 votes
2 answers
63 views

Finding the Size of a File in a Portable Manner (revision 2)

This is a follow up to Find the Size of a File in a Portable Manner (revision). Changes made: The return value of fseek() and ...
Harith's user avatar
  • 9,777
4 votes
2 answers
87 views

Find the Size of a File in a Portable Manner (revision)

This is a follow up to Find the Size of a File in a Portable Manner. What's new: The fast version (POSIX stat()) does not change the position indicator of the ...
Harith's user avatar
  • 9,777
7 votes
2 answers
721 views

Consolidating GNU C's and C23's attributes

C23 has introduced attribute specifier sequences. Consequently, the header below attempts to conditionally define macros for these sequences (for my own use cases). In cases where a compiler does not ...
Harith's user avatar
  • 9,777
2 votes
2 answers
151 views

A small header-only input output library

The library (inspired by stb libraries) attempts to provide some commonly used functions (reading a file into memory, determining the size of a file) that are missing from the C standard library ...
Harith's user avatar
  • 9,777
3 votes
2 answers
115 views

Unpacking a byte into 8 bytes, where the LSB of each byte corresponds to a bit of the original byte

I needed to unpack a byte into the LSBs of each byte in an 8-byte integer. After some testing, I derived a surprisingly efficient and elegant solution that uses magic numbers multiplication, though ...
CPlus's user avatar
  • 948
9 votes
3 answers
2k views

Executing a shell command OS-independently

The goal of the code is to convert a Graphviz DOT file to an SVG file, and it achieves this by creating a child process and executing the "dot" command. ...
Harith's user avatar
  • 9,777
13 votes
5 answers
3k views

Portable old-school filesystem tool

I recently made a tool called mkfh to create a FHS compliant filesystem structure. I aimed to make it as portable as possible, so I wrote it in C89 and also tried ...
Labricecat's user avatar
3 votes
3 answers
691 views

Command line calculator in C

This code is an arithmetic parser as is the code in a previous question of mine. However this parser handles floating point arguments and mathematical functions, and handles them without needing to ...
CPlus's user avatar
  • 948
4 votes
1 answer
746 views

Basic recursive descent parser in C

The purpose of this code is to evaluate simple integer expressions that make use of the C arithmetic and bitwise operators while respecting C operator precedence and parenthesis. I wrote this code ...
CPlus's user avatar
  • 948
4 votes
1 answer
182 views

Vectorized 16-bit addition in Standard C

The idea is to add a given 16-bit number N to each element of an array of 16-bit integers of arbitrary length, taking advantage of 64-bit integer types and instructions to perform the additions 4 at a ...
CPlus's user avatar
  • 948
3 votes
1 answer
463 views

Portable integer to/from little endian conversion in C

Integers need to be converted to a byte array of defined endianness to be reliably and consistently saved and transmitted, and converted back to be accurately received and read. The goal is to be as ...
CPlus's user avatar
  • 948
2 votes
1 answer
199 views

Portable noreturn in C/C++ between compilers

I'm writing a C/C++ (intended to also be valid C code) for having a noreturn macro variable as widely portable as possible between C and C++ compilers. ...
Giuppox's user avatar
  • 163
0 votes
1 answer
167 views

Line-wise input, EOF handling, and behavioral differences between implementations of getchar

I've implemented a menu system where all input calls ultimately go through io_getline, a function which reads a line of input up to the max buffer size or newline (...
Braden Best's user avatar
1 vote
1 answer
85 views

Open, writing to, and closing a configuration file, and error checking the process in C

All this does is safely and reliably opens, writes to, and closes the file. Yet there are so many gotos and the code is quite verbose. I am not even sure that all ...
user244080's user avatar
5 votes
1 answer
330 views

Two cross-platform implementations of getline in C

I created my cross-platform implementations of getline function in C. It takes different arguments and have different return values than 'original' ...
DeBos's user avatar
  • 525
8 votes
4 answers
1k views

Header file that includes all standard C library headers

The Standard C Library consists of various headers files. Often only a few select ones are needed for given code. Other times it is simply convenient coding to include them all in a .c file, even if ...
chux's user avatar
  • 33.6k
0 votes
1 answer
205 views

Polymorphism and inheritance in C99

In the following code I have created the something like the behavior of inheritance and methods in C99 (without vtable). The code compiles without any warnings even with ...
Lin's user avatar
  • 273
2 votes
2 answers
173 views

Platform-agnostic windowing library

I am making a C library that abstracts window creation with support for the new Vulkan API under a unified API; I have a github repository that you can check out. main.c ...
Removed User's user avatar
14 votes
2 answers
3k views

malloc() and free() for Linux with system calls

I have written an implementation of malloc() and free() for Linux using the sbrk() system ...
jess's user avatar
  • 1,378
3 votes
3 answers
192 views

Safely & portably read a value into a predefined integral type of varying size like mode_t

I need to read a value from a text file and put it into a predefined type, in this particular case mode_t. This typedef can have a variety of types underlying it, ...
John Hascall's user avatar
1 vote
1 answer
632 views

Galton Board Simulation

This program is written for Windows 7 under MinGW using gcc. I'm seeking recommendations for improving the program's portability. ...
Verbatim's user avatar
  • 351
4 votes
2 answers
25k views

HTTP request parser in C

I'm implementing a simple HTTP server in C, and this is the first part of it. Basically, it takes a string containing a "raw" HTTP request, and parse it into a ...
nalzok's user avatar
  • 513
5 votes
1 answer
725 views

Modular exponentiation without range restriction

A typical modular exponentiation may be coded using the following algorithm. ...
chux's user avatar
  • 33.6k
4 votes
3 answers
945 views

Portable multithreaded matrix multiplication in C

I essentially took this progam, and made it compile and run on Windows too. Also, I incorporated some nice points made by Toby Speight. matrix.h ...
coderodde's user avatar
  • 29.8k
12 votes
3 answers
27k views

Endianness conversion in C

I have written a simple C header for converting the endianness of short integers and long integers. It uses the GCC macro ...
Jack Wilsdon's user avatar
  • 1,641
4 votes
1 answer
91 views

Secure file system utility functions

For Khronos, I've had to develop these utility functions to help me deal with storing the .wav files. However, they could also be used in a variety of applications....
syb0rg's user avatar
  • 21.8k
18 votes
2 answers
539 views

The birth of my intelligent assistant: Khronos

I've done a lot of reworking to this main file recently, in regards to using a new speech recognition engine and integrating the last reviews suggestions. My question before is going to be phrased ...
syb0rg's user avatar
  • 21.8k
7 votes
2 answers
2k views

Portable byte order conversion

I'm trying to improve the portability of a file format converter, specifically to POSIX platforms other than Linux. I'd appreciate a review of the following functions used for converting between ...
zanyelf's user avatar
  • 73
6 votes
2 answers
33k views

Timestamp function with millisecond precision

I want to be able to print timestamps with milliseconds precision and time_t doesn't provide this. I also want the code to be portable, so operating specific ...
arcomber's user avatar
  • 2,439
0 votes
2 answers
2k views

BMP writer in C

I recently wrote a BMP writer in C: bmpWriter.h ...
LastSecondsToLive's user avatar
3 votes
1 answer
104 views

Non-curses pager in C (revision 2)

In this revision (follow-up of this post) I've fixed reading from stdin, and also tried to minimise the damage caused by typing additional characters. You might want to see my original post on this. <...
user avatar
7 votes
2 answers
96 views

Pseudoportable C script pattern - follow-up

See the initial/previous iteration. I have rewritten the script following the answer of @200_success. Now it looks like this: ...
coderodde's user avatar
  • 29.8k
6 votes
1 answer
88 views

Pseudoportable C script pattern

(See the next iteration.) From time to time, while working with a command line in *nix family of operating systems, we have to write those scripts doing a rather specific task. Usually we use ...
coderodde's user avatar
  • 29.8k
7 votes
2 answers
85 views

Printing the days of the week for every day this year

@chux pointed out that my attempted solution contained several problems. Since I screwed that up so badly, I figure that I should put my revised solution up for review. ...
200_success's user avatar
2 votes
3 answers
2k views

Simple and safe file reader for C

As an exercise to improve my coding ability in C, I have attempted to write a simple and safe file reader. I believe this should be portable as well to major platforms (correct me if I'm wrong). For ...
dev_nut's user avatar
  • 325
8 votes
2 answers
1k views

Making multiple copies of a pattern

Here's a function for making multiple copies of a block of memory in another block of memory. It handles the case when the size of the target is smaller than or not a perfect multiple of the source ...
user avatar
6 votes
2 answers
140 views

Inferring Memory Alignment

The following code is intended to infer the alignment of double. My questions include: Is there a better to do this? Either by refining the code or using an ...
user avatar
10 votes
1 answer
2k views

Recording audio in C 2.0

I posted my audio recording program to Code Review before, and received a stern review along with the other reviews that caused me to rewrite the entire code base. Here is what I would like reviewed: ...
syb0rg's user avatar
  • 21.8k
28 votes
2 answers
42k views

Windows keylogger in C

I have had this keylogger code for a while now (a few years*), and I figured I would put it up for review. Here is what I would like reviewed (in order): Portability - right now, this program can ...
syb0rg's user avatar
  • 21.8k
5 votes
2 answers
357 views

VLC media player watchdog daemon v6

This question is a follow-up to a previous version of this program, which I wrote because I found it annoying that VLC Media Player (which I love) prevents the screensaver from starting after playback ...
JB0x2D1's user avatar
  • 271
8 votes
1 answer
719 views

VLC media player watchdog daemon

I'm looking for bugs, ways to make it more portable or standardized, improvements of any kind. Seems to do what it is supposed to on my Ubuntu 12.04 PC. ...
JB0x2D1's user avatar
  • 271
17 votes
1 answer
2k views

Brainfuck-to-C compiler written in C++

This compiler, implemented in C++, takes brainfuck code and produces a valid (but still obfuscated) C program, which in turn can be compiled to a native binary. Expected usage is as follows: Build ...
200_success's user avatar
5 votes
1 answer
216 views

Portability and "dark corner" gotchas in this "watchdog" program

The following program is intended to "watchdog" a child process, and all subprocesses the child spawns. The intended behavior is: A child process (as specified on the command line) is run in a ...
zwol's user avatar
  • 411
7 votes
1 answer
685 views

UTF-8 character reader function

You may see full code here (note that the link points to the specific commit). Language is "clean C" (that is, a subset of C89, C99 and C++98 — it is intended to compile under all of these standards)....
Alexander Gladysh's user avatar