All Questions
Tagged with cross-platform or portability
105 questions
3
votes
1
answer
711
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 <...
2
votes
1
answer
33
views
Cmake build system for the GenericDictionary
The 3 cmake files presented here are the CMakeLists.txt files used to build the testing for the Generic Dictionary.
The builds and ctest work on Ubuntu 22.04. The builds previously worked on Windows ...
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 ...
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 ...
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 ...
4
votes
2
answers
106
views
TCP socket base class and Winsock implementation
I'm coding a chat application from scratch in modern C++. I'm currently building an interface for interacting with sockets. I want it to be cross platform. Am I approaching platform independence ...
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 ...
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 ...
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.
...
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 ...
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 ...
4
votes
1
answer
745
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 ...
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 ...
3
votes
1
answer
462
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 ...
2
votes
0
answers
117
views
A Python base class for a family of Postgres server manager classes
I'm working on a repo the purpose of which is to create and manage a local PostGIS server. (PostGIS is a bit niche, but it boils down to a few extra spatial data types and built-in SQL function. With ...
1
vote
1
answer
294
views
File Abstraction Library
This library is a layer of abstraction over file operations in C#. It aims to provide easy file IO syntax, and implicit error handling behaviors, to ensure robustness in scenarios including, but not ...
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.
...
2
votes
1
answer
99
views
AST node class generator
Given two hashes, my script generates two (poorly formatted) C# source files containing some classes that represent several AST nodes a programming language needs and an implementation of the Visitor ...
1
vote
1
answer
153
views
Connect Four in C++
This is a library that implements the logic of Connect Four.
There's nothing related to graphics or user input here. This library is supposed to be integrated into any environment where one could run ...
2
votes
1
answer
110
views
Safely renaming/moving files in Node (cross platform)
My goal is to create a function that safely renames files by adding numeric increments if the file is found at the destination, without using a third party library.
Having a source file ...
-2
votes
1
answer
131
views
Write portable Git aliases
The following aliases return all the same number of results, on my Cygwin (on Windows):
...
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 (...
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 ...
2
votes
1
answer
210
views
C++ exception class for error reporting, compatible with C++98 through C++20 (ver 2)
This question contains revised code from the question
What should a C++ error reporting exception class have to be portable across language versions?.
I summarize what is different from that code at ...
8
votes
2
answers
321
views
What should a C++ error reporting exception class have to be portable across language versions? (ver 1)
Link to revised (ver 2) question
This question contains the first version of the code for the task
explained below. The revised version is at C++ exception class for error reporting, compatible with ...
3
votes
1
answer
229
views
Text centered in a circular component
I have surrounded my initials with a circle. This is intended to be a re-usable component in a responsive layout. (When it is re-used the text will always be two letters, and the font won't change. It ...
4
votes
2
answers
139
views
*nix, *bsd, etc basic `tput` color setup
My goal with the below piece of POSIX shell code was to address the more platforms the better with shell tput colors. With this code, I now start all of my scripts, ...
2
votes
0
answers
48
views
Bash script to scp specific, most-recent files from remote server
I'm writing a helper script that I wish to be able to share with my co-workers. We all work using macOS Mojave, but all have their own shell configurations. For example, I actually use ZSH and bash 5....
12
votes
1
answer
223
views
Not so Excellent Knight's Tour
Note: This is part of a set of demo applications I'm writing for colleagues to show we're not limited to VBA when dealing with Excel. Considering our IT challenges (no admin on-site & no local-...
7
votes
0
answers
757
views
Unity3D shader for rendering 2D sprites with a pseudo-glitch effect
I'm making a puzzle game in Unity with sprite-based graphics. When the game is paused, I want to hide most game elements, because I don't want the player to be able to pause and leisurely think about ...
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' ...
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 ...
2
votes
0
answers
817
views
A portable cross platform C++17 method to retrieve the current date and time
I am working on a utility function to get the current date and time. My objective is to do this in a generic and portable way. I would like to stay way from platform specific code to allow the ...
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 ...
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
...
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 ...
0
votes
1
answer
674
views
Creating a Compatibility Shim for ExampleClass to be targeted both to .net framework and .net core 2.0
Intro: Before showing the actual code for review, let me show you an ExampleClass to create a shim for.
...
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, ...
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.
...
1
vote
2
answers
96
views
Portable (Linux, Cygwin,...) Makefile for my own Shell OpenSSL file en-/decryption scripts
Let it be clear that in this question I ask for further guidance with my current version of Makefile used for my own Shell OpenSSL file en-/decryption scripts, not ...
8
votes
1
answer
139
views
Portability in using up-and-coming library features
Currently, some library features are not in std that comes with the compiler, but may be in std::experimental or may not be ...
3
votes
1
answer
98
views
Function declarations using macros to support multiple platforms
I wrote a C++ plugin that retrieves screen pixel. It works on Windows and Android. I noticed that dllexport is only required on Windows but not on Android and ...
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 ...
5
votes
1
answer
725
views
Modular exponentiation without range restriction
A typical modular exponentiation may be coded using the following algorithm.
...
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
...
7
votes
1
answer
345
views
Wrapper to enhance a program to translate from LTL formulae to Büchi automata
The following is a script that is supposed to act as a wrapper for ltl2ba, a program which transforms LTL formulas into Buchi Automatons encoded in the Promela language. The wrapper adds a limited set ...
1
vote
1
answer
262
views
Conditionally loading a terminal or cli with node.js
I've been working a side project recently, when ever I have time, to make a small script that determines what Command Line Interface to load using node.js and its ...
1
vote
1
answer
2k
views
Forced and easy hton/ntoh conversion
Context:
When sending message across the network, the sender has to convert the message from host byte order to network byte order and the receiver has to do the the reverse - network order to host ...
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 ...
8
votes
1
answer
925
views
Guessing the JDK home directory
My project is using a specific version of JDK which is jdk-6 and the default JDK_HOME path will vary from distribution to distribution, so I wrote a script to guess it. Is there any way to do this ...