Reading List

The Selfish Gene
The Psychopath Test: A Journey Through the Madness Industry
Bad Science
The Feynman Lectures on Physics
The Theory of Everything: The Origin and Fate of the Universe


ifknot's favorite books »

Sunday, 19 April 2026

DOSBox_joker.png CGA mode 6 "hi res"

Getting Zed and Clangd to Be Useful for the Retro Programmer

My editor of choice is Zed. It is fast, modern and minimal. My compiler is Open Watcom (which is a modernised Watcom) ancient and idiosyncratic but correct for the IBM XT target I am writing for. The problem is that clangd, the language server that Zed uses for C and C++ code, has opinions about my code - strong opinions.

As I have argued elsewhere, modern language servers and retro compilers are not natural bedfellows. Clangd expects C17, not 8086 assembly with __fastcall calling conventions and inline __asm blocks. Open Watcom accepts all of that happily, because it was built for the retro target, but clangd was not. The two do not speak the same dialect, and the result, without configuration, is an editor full of red squiggly underlines under perfectly valid code.

Consider then, a typical function from my codebase:

void __fastcall cga_hi_res_plot(cga_coord_t x, cga_coord_t y, cga_colour_t colour) {
   __asm {
      .8086
       mov     ax, x
       
       etc...
  }
}

Clangd flags __fastcall as an unsupported calling convention. It flags __asm as unknown syntax. It has no idea what .8086 means. The code compiles without complaint under Watcom and the XT runs it beautifully, but my editor thinks I am writing nonsense.

The Solution a .clangd File

The most reduced form of a working configuration for this problem is a .clangd yaml file in the project root directory that Zed will honour:

CompileFlags:
Add: [-xc, -Wno-ignored-attributes, -fms-extensions]
Remove: [-std=c99]

The -xc flag forces clangd to treat the code as C rather than Objective-C++, which for reasons I do not fully understand is sometimes the default. The -Wno-ignored-attributes flag suppresses the warning about __fastcall being unsupported, which is a lie but a lie we can live with. The -fms-extensions flag embraces the Microsoft and Watcom dialect, which helps with the rest of the weirdness. Removing -std=c99 prevents clangd from insisting on a language standard that my code does not fully follow because neither does Watcom.

The Include That Was Not Unused

A second problem emerged after the squiggles were gone. I have a lookup table for CGA row offsets:

#include "cga_lookup_table_y.h"   // clangd says: unused and paints it with yellow squiggles

The header is used extensively, but it is used inside __asm blocks. Clangd cannot see past the veil of inline assembly, so it flags the include as dead code. This is a false positive, but it is a persistent one.

The solution is a pragma from the Include-What-You-Use (IWYU) tooling:

#include "cga_lookup_table_y.h"   // IWYU pragma: keep

This communicates to the analyser that the inclusion is intentional, even if the static analysis cannot observe its usage. The warning disappears, the header remains, and the code continues to work.

Conclusion

So, fellow retro programmers, you can have best of both worlds. With Zed and .clangd configuration you can transform a hostile language server into a useful assistant. The defining properties of such a configuration are that it accepts non-standard calling conventions with -Wno-ignored-attributes, accepts the Watcom dialect with -fms-extensions, preserves includes hidden behind assembly with // IWYU pragma: keep, and - most importantly - lets you keep code completion.

Sunday, 27 July 2025

Applying Design by Contract to C

                   Exploring a practical approach to bringing DbC principles to a language that has a bad reputation for safety.

Synopsis

Design by contract was first coined by Bertrand Meyer in connection with the Eiffel programming language, and it was described in various articles starting in 1986, as well as in his book "Object-Oriented Software Construction" published in 1988 and 1997. The concept emphasizes defining formal interface specifications for software components, akin to business contracts. 

My background reading suggests that Design by Contract (DbC) has never been mainstream and, even

Saturday, 17 October 2020

Reading dumb data into the C++ heterogeneous data_frame

 

Ingest some CSV

Last month I presented an R-ish data_frame class as a small side project, this month I present a C++ equivalent of the R read.csv()function to import data into a data_frame class.

Ongoing development is at the github repo: https://github.com/ifknot/rpp

To recap the motivation for the C++ heterogenous  data_frame class was two-fold:
  1. Runtime handling of dumb data whose format, types, and fields are unknown.
  2. Enable data science skill transfer from the R functional programming environment into C++.
The motivation for the read_csv()function remains the same as that for heterogenous the  data_frame class:

"I want to be able to do the same sort of thing that I do R, but in C++".

Which, this time around, means that I want to be able to use one of the easiest and most reliable ways of getting data in - text files.

In particular CSV (comma-separated values) files. The CSV file format uses commas to separate the different elements in a line, and each line of data is in its own line in the text file, which makes CSV files ideal for representing tabular data - i.e. the  data_frame class.

Saturday, 5 September 2020

A heterogeneous data frame in C++

 

Organise your data the R way

NEW! - more stuff and in a github repo - https://github.com/ifknot/data_frame

I like R for statistics. The variables in R are lexically scoped and dynamically typed. 

I like C++ for just about everything else. C++ is a strongly typed language and it is also statically-typed; every object has a type and that type never changes.

I want to do some simple statistics in C++ but I can't imagine doing that without a heterogenous Data Frame.

I want to be able to do what I do in R - desiderata:


But in C++ - ipsa:


It does this (unlike R in C++, indexing begins from 0)


Here's how...

Wednesday, 15 July 2020

PiDP11 211BSD Jove cursor key bindings




JOVE - How do you keymap VT100 arrow keys?

I found the answer in a 1991 comp.editors Google Group or rather 3 answers courtesy of  Alan Coopersmith (Open Computing Facility, Berkley) quote...

There are 3 basic solutions (all of which are commands put in your
.joverc file):
1. Upgrade to version 4.14 (I was told 4.9 really means 4.09) and use:
>       make-keymap vt100-map
>       bind-keymap-to-key vt100-map ^[[

>       bind-to-key next-line ^[[B
>       bind-to-key previous-line ^[[A
>       bind-to-key forward-character ^[[C
>       bind-to-key backward-character ^[[D
2. Use this (not sure which version):
             bind-to-key prefix-3 ^[[

             bind-to-key next-line ^[[B
             bind-to-key previous-line ^[[A
             bind-to-key forward-character ^[[C
        bind-to-key backward-character ^[[D
3. Stay with version 4.9 and use:
        bind-to-key ansi-codes ^[[
        bind-to-key ansi-codes ^[O
I will use #3 since it doesn't require bothering the overworked/unpaid
OCF staff to install a new version.  It is also the simplest, but only
works with vt100/ANSI term types.  If you want to do assign keys on a
vt220 or a Sun or anything else that doesn't use the vt100 key codes, you
need a version past 4.9.  (To find out what version you have type M-X
version).
I used solution 3. and that worked just fine.


PiDP11 211BSD upgrade to patch level 469 (Chase Covello 2019)


Upgrade 2.11BSD to patch level 469 - Chase Covello (2019) github

Chase Covello's 2.11BSD patch 469 adds a number of features not least of which is the EMAC-like editor jove as a more humane editor than vi.

Display high-resolution graphics with the Tektronix 4010 terminal emulator

Log in as user tektronix. The directories under /home/tektronix/ contain example programs and plot files for use with Rene Richarz’ Tektronix 4010 graphics terminal emulator. [manual]

Saturday, 11 July 2020

PiDP 11 ~/php.sh returns 0 Version GLIBC_2.28 not found



The latest version of smh for the PiDP11 requires glibc 2.8 unfortunately Raspbian stretch has version 2.4 and so your updated install of smh wil not work.

However, it is possible to update stretch to buster and this will solve the problem.

How to do this is a straight cut & paste from DDuck at
 https://www.domoticz.com/forum/viewtopic.php?t=30219

Let’s first update all the currently installed packages by running the following command.
CODE: SELECT ALL
sudo apt update
sudo apt dist-upgrade -y
Next, let’s go ahead and also update the Raspberry Pi’s firmware.
We can do that by running the command below on our Raspbian installation.
CODE: SELECT ALL
sudo rpi-update
Now that we have prepared our Raspbian Stretch installation, we can now start the process of moving to Buster.

Friday, 22 May 2020

Windows 10: Clean out unused COM ports


Do your COM ports look like this?

Then you've probably just discovered Windows is rubbish at handling USB COM port devices if you plug and unplug them willy-nilly.

How to clean out your COM port cruft:


  1. Run Command prompt with the elevated privileges.
  2. To enable device manager show absent device(s) enter devmgr_show_nonpresent_devices=1 
  3. Restart computer & Run Command prompt with the elevated privileges.
  4. Enter cd c:\Windows\system32 

  5. Enter devmgmt.msc
    (device manager is now running elevated and showing 'nonpresent' devices)
  6. In device manager activate the display of hidden devices from the top menu by clicking View > Show hidden devices.
    (This will list all devices including those that are no longerconnected)
  7. Expand the Ports (Com&LPT) section, all the COM ports that have ever been created will be displayed (the hidden and unused ones being in grey).
  8. Uninstall to your heart's content (right click, select Uninstall).


Tuesday, 28 April 2020

Undefined reference to operator delete(void*) C++ AVR pure virtual and __cxa_pure_virtual()

 __cxa_pure_virtual()
&
Undefined reference to operator delete(void*)


C++ Programming for MCUs such as the Atmel AVR family can be both very productive and also very frustrating as one learns to work without libstdc++ when using certain MCU toolchains e.g.
  • C++ AVR Studio 
  • C++ avr-gcc 
  • C++ Arduino 
Whilst it is generally well known that the MCU programmer must provide their own versions of new and delete[1] it is less well known that the C++ programmer using pure virtual member functions must provide an implementation for __cxa_purevirtual() or face some very confusing errors!

Depeding on toolchain the programmer may be lucky and be notified:

undefined reference to `__cxa_pure_virtual'

What is __cxa_purevirtual()?[2]

Friday, 13 December 2019

The Joy Programming Language #1

Functional Programming in Joy #1
Just because something is obscure does not make it unworthy of study.


What is Joy?

Joy is a pure, concatenative, functional, scalar programming language.
Joy is pure because it does not contain assignment.
Joy is functional because computation consists of the evaluation of expressions.
Joy is concatenative (and not applicative) because
  • The elementary well-formed expressions of Joy are monadic functions of a nameless data stack.
  • If X and Y are well-formed expressions, then the concatenation of X and Y is well-formed.
  • If Z is the concatenation of X and Y, then the value of Z is the composition of the values of X and Y.
Sadly, the official website is no longer hosted by La Trobe University however there is a reasonably complete mirror hosted by Kevin Albrecht and the Wikipedia page is helpful.

Hello World in Joy?

"Hello, world!\n" putchars .

Quicksort in Joy?

DEFINE qsort ==
  [small]            # termination condition: 0 or 1 element
  []                 # do nothing
  [uncons [>] split] # pivot and two lists
  [enconcat]         # insert the pivot after the recursion
  binrec.            # recursion on the two lists (full-stop ends the define)

Who invented Joy?

Manfred von Thun was the inventor of the Joy programming language.

According to the LaTrobe University Alumni news:

"Alumni and staff will be saddened to hear of the death of Manfred von Thun on 23 October after a long illness. Manfred was a member of the philosophy department from early 1972 until his retirement in 2003, but remained an honorary associate until 2009. Manfred specialized in logic, philosophy of science, philosophy of mind, computer programming and cybernetics. He was also renowned for developing the computer programming language, Joy. He will be sadly missed."


Joy’s inventor, Manfred von Thun 


Sunday, 8 December 2019

Enable CGI Apache2 (Debian et al)

C++ Server Side Web Development

CGI, the Common Gateway Interface is a simple way to write web applications. It is by no means the fastest and some may say that:

"If you're planning to write your web application in C++, it would be total waste to then interface it as CGI.

My suggestion would be to build it asynchronous using ASIO (Asynchronous I/O). With that you can build blazing fast web service (combine with nginx as a reverse-proxy and statics server for best effects); Combine that with template library like Wt and you're ready to serve tens of thousands request per second from a single server.

Whether this is practical alternative to dynamic language web framework is another issue." vartec 2013 

However, it is a simple way of demonstrating server side web development with a number of programming languages, including C++.

Install Apache2

To support websites built with C++ using the CGI requires webserver software capable of (which is all of them) and configured to enable (not all of them) execute code in a cgi directory.

Monday, 1 January 2018

C++ Mellor-Crummey & Scott (MCS) Lock - Milestones In Computer Science


I have been reading Herlihy, Maurice; Shavit, Nir. The Art of Multiprocessor Programming, Revised Reprint. Elsevier Science. (Kindle Edition) and converting the Java lock code into C++ here is my favourite so far: 

The Mellor-Crummey & Scott Spin Lock

The Mellor-Crummey & Scott (MCS) Lock, due to John Mellor-Crummey and Michael Scott improves upon their ticket lock by expanding a spinlock into a per-thread structure, an MCS lock is able to eliminate much of the cache-line bouncing experienced by simpler locks, especially in the contended case. 

The MCS Lock use an explicit linked list of synchronization variables, into which threads' synchronization variables are enqueued by order of arrival and avoids thread starvation by guaranteeing that an enqueued thread will, eventually, get access.

The MCS Lock is, therefore, fair and scalable and is the primary example of linked list queue lock family of locking strategies.

Its creators were awarded the 2006 Edsger W. Dijkstra Prize in Distributed Computing for their 1991 paper, "Algorithms for Scalable Synchronization on Shared-Memory Multiprocessors."

Tuesday, 9 May 2017

Tic-Tac-Toe Bitboards


CPE1704TKS

Board Games are, generally speaking, a collection of position based states and whilst it might seem intuitive for games like draughts, othello, chess, etc to have their positional states encoded in arrays and matrices of integers or floats it isn't efficient and it certainly isn't easy to reason about those states. So, quite early on (1950s and 1960s) it was discovered, and rediscovered, that it is more efficient to represent game states as 1 dimensional collections of bits and, more importantly, much easier and faster to reason about those states using boolean operators.

Such 1D bit arrays are termed bitboards and reach their zenith of complexity and utility in the game of Chess.

But it's not just Chess that can benefit from bitboards so can the humble game of Tic-Tac-Toe (a.k.a. Noughts & Crosses if you're Blighty based).


Tuesday, 25 April 2017

LNMHH Towards A Full Stack Developer Jack-Of-All-Trades



LNMHH

LNMHH is my alternative solution stack to the archetypal LAMP model of web service stacks. Using the LAMP naming convention as an acronym of the names of its composing five open-source components it consists of: 
  • Linux operating system
  • Nginx HTTP Server
  • MySQL relational database management system (RDBMS)
  • Hip Hop Virtual Machine (HHVM) virtual machine designed for executing programs written in Hack and PHP

LNMHH is intended to be the modern, typesafe approach to building dynamic web sites and web applications.

Other supporting members of the cast are also included, not least of which is the excellent Hack Lang compatible editor Nuclide (built atop Atom) for its remote development strengths:
  • Nuclide client development environment for remote & local Hack projects
  • Nuclide server to enable remote development
  • Watchman utility that watches files/directories for changes and performs actions on change
  • Composer tool for dependency management in PHP Hack Lang
  • XHP extension to Hack for inline XML/HTML for custom and reusable HTML elements
The initial LNMHH test stack was set up on a Digital Ocean Droplet...

Saturday, 22 April 2017

I have a pipe-dream! One idiot's efforts in programming land...

Paper 53 client-server interaction diagram

  • I want to learn Hack - Facebook's typesafe version of PHP and use it with HHVM to serve up game connections for simple board games.
  • I want to learn QML - Qt's cross platform user interface markup language with inline JavaScript (which I will also need to learn) for simple board game clients e.g. Tic-tac-toe and Snakes & Ladders.
Importantly, I have no idea how to do any of this but even if it all crashes and burns I will hopefully have learned along the way - and, just maybe, the journey will be of useful interest to others.

Thursday, 17 November 2016

Verify the integrity of a flash/SD card on a Mac using F3 and F3X



TL;DR I just want an App for that but I'm cheap and don't want to pay - go here

Command Line Testing your SD card using F3 on Mac OS X


You love the command line and want to test your SD card? 


The software “F3” (either meaning “Fight Flash Fraud” or “Fight Fake Flash” according to its author Michel Machado) is an open-source implementation of the same algorithm h2testw employs to determine the integrity of a memory card (or any volume you mount on your Mac for that matter).

Sunday, 6 November 2016

Vigil++ Because eternal moral vigilance is no laughing matter.


no expect
It's Vigil for C++ but with the chance of redemption!

Install Me: Bit Bucket

Bob Nystrom has created the excellent Vigil programming language that auto-deletes any deviant code from the code base! Vigil++ is a denomination that offers redemption! Whilst it does deliver implore and swear macros, it does not adhere to the extreme run time vigilance of Vigil by deleting code but rather throws a moral-exception and a frowny face ಠ_ಠ as appropriate admonishment! But whilst you will be chastened, you will also be given the chance of redemption by being able to recover from the moral-exception.

Why Vigil++?

Saturday, 24 September 2016

Site testing with Google Skipfish


skipfish


Skipfish is Google's active web application security reconnaissance tool. It prepares an interactive sitemap for the targeted site by carrying out a recursive crawl and dictionary-based probes. The resulting map is then annotated with the output from a number of active (but hopefully non-disruptive) security checks. The final report generated by the tool is meant to serve as a foundation for professional web application security assessments.


https://code.google.com/archive/p/skipfish

Install:


brew install skipfish 


But...


It looks like the Homebrew package manager port of Skipfish is broken. It doesn't properly changes the path of the signatures directory to point to /usr/local/Cellar/skipfish/2.10b/libexec/signatures.


Fix:

skipfish -z /usr/local/Cellar/skipfish/2.10b/libexec/signatures ...other commands

Setup:

touch dictionaries/empty.wlln -s dictionaries/empty.wl skipfish.wlmkdir ../out


Run:


skipfish 
-z /usr/local/Cellar/skipfish/2.10b/libexec/signatures -o ../out/ http://example.com


Results:

Then view the result in your browser:

firefox ../out/index.html



Just a friendly advice, Don’t be evil!


Be careful where you use this tool, this is an extremely powerful crawler which can eat up any websites’ bandwidth overnight. 




Saturday, 10 September 2016

Migrating to Bitbucket and turning my markdown frown upside down with Dillinger WYSIWYG and Cloudup image drop spot.

Check out my fancy markdown https://bitbucket.org/ifknot/liblog


Why move from GitHub to Bitbucket?


Bitbucket, similar to GitHub, is a web based GIT hosting service for your projects. It offers free private repositories with free private wikis on accounts of up to 5 users(!) and you can switch any repo public and back again anytime. So develop in private and publicise when you're ready. 

GitHub’s  free account doesn’t allow for private repos and their lowest paid option (for organizations) only allows up to 10 private repos. Bitbucket, on the other hand, offers unlimited private repos. 

It's easy to import directly from GitHub with the click of a button - well done Bitbucket.

What to move first?

I moved over liblog the logging software that I first blogged about way back in Jan 2014 but wanted to have a nice front piece for when I chose to make it public. This can be easily achieved using markdown in a README.md file pushed to the repo. 


Markdown frown. 

dillinger.io
Markdown is (quite) easy but slow to hand roll but with the excellent online WYSIWYG markdown editor Dillinger "Type some Markdown on the left... see HTML in the right" I found it pleasurable to work with and get some decent looking results.

Gratis image drop.

A free account on Cloudup gives you space to drop pics/vids/music/docs and have nifty short URLS to them for your markdown/blog/web

Saturday, 27 August 2016

Fontastic! Meaningful programming ligatures with FiraCode

Fira Code: monospaced font with programming ligatures


Fira Code is an extension of the Fira Mono font containing a set of ligatures for common programming multi-character combinations. It is easy to install in OS X and works with Qt Creator.

I think I like it :)