Skip to content

Instantly share code, notes, and snippets.

View johnmcfarlane's full-sized avatar

John McFarlane johnmcfarlane

View GitHub Profile
// Copyright John McFarlane 2018.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file ../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// mechanically retrieved, single-header version of CNL library
// https://github.com/johnmcfarlane/cnl
#if ! defined(CNL_COMPLETE_H)
// Copyright John McFarlane 2018.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file ../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// mechanically retrieved, single-header version of CNL library
// https://github.com/johnmcfarlane/cnl
#if ! defined(CNL_COMPLETE_H)
// Copyright John McFarlane 2018.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file ../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// mechanically retrieved, single-header version of CNL library
// https://github.com/johnmcfarlane/cnl
#if ! defined(CNL_COMPLETE_H)
@johnmcfarlane
johnmcfarlane / begin(C++).md
Last active June 3, 2024 07:33
Resources for C++ beginners
@johnmcfarlane
johnmcfarlane / warning_level_test.cpp
Created August 28, 2018 12:42
code to test warning level of C++ translation unit
// code to test warning level of C++ translation unit;
// works with compilers which support `-Wpedantic` flag
// any warning level: 'extern' variable has an initializer [-Wextern-initializer]
// -Wall: "unused variable 'n' [-Wunused-variable]"
// -Wextra: "missing field 'b' initializer [-Wmissing-field-initializers]"
extern struct { int a, b; } n = {sizeof(void(*)(int))};
// -Wpedantic: "variable length arrays are a C99 feature [-Wvla-extension]"
int evoke_pedantic_warning_vla(int n) { int a[n]; return a[3]; }
@johnmcfarlane
johnmcfarlane / The_Quest_for_Embedded_C++.md
Last active February 21, 2023 18:36
Links related to problems embedded ppl have with C++ and the things we're doing to fix that

The Quest for Embedded C++

There are many problems with C++ and the embedded community which mean they don't get along so well. Here are some resources that might help explain the problems and their solutions.

The Problem

// it's probably a good thing that CompilerExplorer's #include<https://> feature isn't recursive!
/*
The MIT License (MIT)
Copyright (c) 2014-2019 Hana Dusíková (hanicka@hanicka.net)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
@johnmcfarlane
johnmcfarlane / cnl_complete_17_128bit.h
Last active May 13, 2019 00:22
Single-header CNL library for C++17 with 128-bit integer support
// Copyright John McFarlane 2018.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file ../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// mechanically retrieved, single-header version of CNL library
// https://github.com/johnmcfarlane/cnl
#if ! defined(CNL_COMPLETE_H)
@johnmcfarlane
johnmcfarlane / cnl2.h
Created April 17, 2019 21:57
number<> & pals
#include <functional>
#include <type_traits>
#include <utility>
namespace cnl2 {
////////////////////////////////////////////////////////////////////////////////
// Arithmetic - is a something that supports arithmetic operators
//
// As well as a fundamental arithmetic type (unsigned short int, __int128, etc.)
// a class-based type (a pack<> or a number<> instantiation) although bool is