Skip to content

Instantly share code, notes, and snippets.

View dlOuOlb's full-sized avatar
🍀

#OuO dlOuOlb

🍀
View GitHub Profile
@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+ */
@dlOuOlb
dlOuOlb / list.md
Last active May 6, 2024 12:07
兎鞠まり🥕
@dlOuOlb
dlOuOlb / main.c
Created February 12, 2022 12:02
A singleton example in C.
#include "uSingleton.h" /* uSingleton */
extern signed int main( void ) { return uSingleton.Method_( 0 ); }