Skip to content

Instantly share code, notes, and snippets.

View dlOuOlb's full-sized avatar
🍀

#OuO dlOuOlb

🍀
View GitHub Profile
@dlOuOlb
dlOuOlb / main.c
Last active January 22, 2026 06:58
An example of C23 function properties: effectless, idempotent, independent, and stateless.
#if !__STDC__ || __STDC_VERSION__ < +202311L
# error "This code is written in standard C23."
#else
static bool ψ = true;
static bool non_independent( void ) { return ψ; }
static void non_effectless( register const bool ζ ) { ψ = ζ; return; }
static bool non_stateless( register const bool ζ ) { static bool φ = true; return φ = φ && ζ; }
static void non_idempotent( register bool ξ[ const restrict static sizeof "" ] ) { *ξ = !*ξ; return; }
@dlOuOlb
dlOuOlb / main.c
Last active January 19, 2025 10:53
An example of XML documentation comments.
#if !__STDC__ || __STDC_VERSION__ < 199901L || !__STDC_HOSTED__
# error "This example requires a C99 compiler with a conforming hosted implementation."
#else
# include <stdio.h> /* puts */
# include <stdlib.h> /* EXIT_(FAILURE|SUCCESS) */
/// <summary>Every C program coded to run in a hosted execution environment contains the definition (not the prototype) of a function named <see cref="main"/>, which is the designated start of the program.</summary>
/// <returns>If the return statement is used, the return value is used as the argument to the implicit call to <see cref="exit"/>() (see below for details). The values zero and <see cref="EXIT_SUCCESS"/> indicate successful termination, the value <see cref="EXIT_FAILURE"/> indicates unsuccessful termination.</returns>
/// <param name="argc">Non-negative value representing the number of arguments passed to the program from the environment in which the program is run.</param>
/// <param name="argv">Pointer to the first element of an array of <paramref name="argc"/
@dlOuOlb
dlOuOlb / voider.js
Created January 1, 2024 06:16
Explicitly ignoring a return value.
'use strict';
/** This class provides a static property `void` which just __ignores__ any assigned value. */
export default class extends null
{
static get void( ) { return; }
static set void(_) { return; }
}
@dlOuOlb
dlOuOlb / main.c
Last active January 1, 2024 06:08
Measuring a maximum memory block size.
#if !__STDC__
# error "This code is written in standard C90."
#else
# include <stdio.h> /* printf|size_t */
# include <stdlib.h> /* EXIT_(FAILURE|SUCCESS)|free|realloc|size_t */
static size_t xSize_( void )
{
auto struct { size_t Size; void *Void; } New, Old = { 0U, 0 };
auto size_t Mask = ~Old.Size;
@dlOuOlb
dlOuOlb / CMakeLists.txt
Last active January 15, 2023 11:55
Changing the font color on a console.
CMake_Minimum_Required( VERSION 3.12 )
Project( "MyColor" LANGUAGES "C" VERSION "0.0.0.0" DESCRIPTION "Changing the font color on a console." HOMEPAGE_URL "https://gist.github.com/dlOuOlb/6a491c71081bfa8189ed6553ac250bf4" )
Set( CMAKE_C_STANDARD "90" )
Set( CMAKE_SUPPRESS_REGENERATION "ON" )
Set( CMAKE_BUILD_TYPE "Release" )
Set( CMAKE_CONFIGURATION_TYPES "Release" )
Add_Executable( "MyColor" "main.c;names.c;values.c;" )
@dlOuOlb
dlOuOlb / about.md
Created November 5, 2022 03:46
The C++ main function with read-only string arguments.

Summary

flowchart TB
	Old.Count("signed int") & Old.Array("char **") --> New.Class

	subgraph Old.Main["main"]
		New.Class("std::vector&lt;std::string&gt;") --> New.Main["Main"]
	end
@dlOuOlb
dlOuOlb / about.md
Last active January 1, 2024 06:10
The C main function with read-only string arguments.

Summary

flowchart TB
	Old.Count("signed int")
	Old.Array("char **")

	Old.Count --> New.Count
	Old.Array -- "undefined behavior" --> New.Array
@dlOuOlb
dlOuOlb / dlOuOlb.numeric.checked_cast.ixx
Last active January 1, 2024 06:11
A function template about checked integer casting.
#if __cplusplus < 202002L
# error "This code is written in C++20."
#else
export module dlOuOlb.numeric:checked_cast;
import <format>; /* std::format */
import <limits>; /* std::numeric_limits */
import <stdexcept>; /* std::(overflow|underflow)_error */
import <string>; /* std::(to_)?string */
@dlOuOlb
dlOuOlb / load.c
Last active July 23, 2022 11:49
Saving and loading a text file.
#if !__STDC__ || __STDC_VERSION__ < 199901L
# error "This code is written in standard C99."
#else
# include <stdio.h> /* f(close|error|open|read)|size_t */
static signed int xTest_( const size_t Charge, const size_t Budget, char Text[ const restrict static Budget ] ) { return Budget <= Charge || ( Charge[ Text ] = 0 ); }
extern _Bool uLoad_( const size_t Length, char Text[ const restrict static Length ], const char Path[ const restrict static 1U ] )
{
auto const char Mode[ ] = { "r" };
@dlOuOlb
dlOuOlb / dlOuOlb.containers.buffer.ixx
Last active July 31, 2022 12:34
A class template about a buffer of uninitialized items.
#if __cplusplus < 202002L
# error "This code is written in C++20."
#else
export module dlOuOlb.containers:buffer;
import <concepts>; /* std::(regular|totally_ordered) */
import <cstddef>; /* std::(ptrdiff|size)_t */
import <iterator>; /* std::(\w+_)?iterator(_\w+)? */
import <ranges>; /* std::ranges::\w+ */