nameandnature: Giles from Buffy (Default)
Memory barriers in C
What it says on the tin.
(tags: C memory threads)

Originally posted at Name and Nature. You can comment there (where there are currently comments) or here.

nameandnature: Giles from Buffy (Default)
What is Strict Aliasing and Why do we Care? · GitHub
More type punning worries.
(tags: aliasing c programming punning)

Originally posted at Name and Nature. You can comment there (where there are currently comments) or here.

nameandnature: Giles from Buffy (Default)
post modern C tooling – draft 5

(tags: tools programming C)

‘My ties to England have loosened’: John le Carré on Britain, Boris and Brexit | Books | The Guardian
“At 87, le Carré is publishing his 25th novel. He talks to John Banville about our ‘dismal statesmanship’ and what he learned from his time as a spy”
(tags: spies intelligence MI5 MI6 le-carre politics)
The New Zealand Shootings: The Untold Stories | GQ
A moving account of the shootings and their aftermath. Via Metafilter.
(tags: shooting terrorism racism new-zealand)
How Derren Brown Remade Mind Reading for Skeptics | The New Yorker
Introducing Derren Brown to the Americans. Via Mefi.
(tags: magic derren-brown mentalism)
WSJ, WaPo, NYT Spread False Internet Law Claims | Cato @ Liberty
Rebutting nonsense about the supposed publisher/platform distinction in Section 230 of the US’s Communications Decency Act. From the Cato Institute, so can’t be dismissed as leftist propaganda.
(tags: law censorship internet)

Originally posted at Name and Nature. You can comment there. There are currently comments.
nameandnature: Giles from Buffy (Default)
Type punning isn’t funny: Using pointers to recast in C is bad.
A common C programming technique (casting between pointers to structures) leads to problems when strict aliasing is turned on (as it is if you set -O2 -O3 in gcc).
(tags: C programming casting punning)
Type Punning, Strict Aliasing, and Optimization – Embedded in Academia
More on the type punning/aliasing business.
(tags: C punning aliasing programming)

Originally posted at Name and Nature. You can comment there. There are currently comments.
nameandnature: Giles from Buffy (Default)
Deep C (and C++)
The differences between shallow and deep understanding in C/C++ or how to ace the technical interview.
(tags: programming C interview)

Originally posted at Name and Nature. You can comment there. There are currently comments.
nameandnature: Giles from Buffy (Default)
Delta Pointers: Buffer Overflow Checks Without the Checks
Using the top bytes of pointers to implement efficent out-of-bound detection.
(tags: security C pointer programming overflow)

Originally posted at Name and Nature. You can comment there. There are currently comments.
nameandnature: Giles from Buffy (Default)
Bit Twiddling Hacks
A collection of code snippets for doing useful things (sign extension, determine whether a number is a power of two, and so on).
(tags: bit-twiddling programming algorithms c hacks twiddling)
Anti-Brexit traitors outed on twitter
UKIP voters in “shit thick” shocker. Also features Louise Mensch.
(tags: twitter ukip funny brexit satire)
Horse! | Start here: See horse, Say Horse! – The Rules of Horse!
Horse!
(tags: funny game horse)

Originally posted at Name and Nature. You can comment there. There are currently comments.
nameandnature: Giles from Buffy (Default)
cmocka – unit testing framework for C
Nifty unit test framework which does the checking arguments and providing return values from stub/mocked functions which I tend to spend a bit of time re-creating each time I write a test.
(tags: test development programming testing unit-test C)
What cohabiting couples can to do put their financial house in order | Money | The Guardian
(tags: cohabitation finances will legal law money)

Originally posted at Name and Nature. You can comment there. There are currently comments.
nameandnature: Giles from Buffy (Default)
Implementing non-recursive make
Recursive makes are considered harmful. Here’s a recipe for a non-recursive one where you can still put project files in subdirectories.
(tags: make programming nonrecursive makefiles build software)
Embedded in Academia : Proposal for a Friendly Dialect of C
John Regehr and friends note that C compilers aggressive optimising around use of constructs the spec says are “undefined” can lead to unexpected behaviour. They propose a friendly C dialect where compilers would produce unspecified values in response to use of these constructs, but would not feel free to make demons fly out of your nose.
(tags: C programming language software-engineering)
The Left must reject the relativism at the heart of the Rotherham scandal | Left Foot Forward
This, from Al Razi of Ex-Muslim Forum, seems a sensible response, although as the worlds only impartial observer, I’d say that both the class of the victims and the race of both victims and perpetrators contributed to the horrors being ignored for so long. The Guardian will only talk about the former and the Telegraph about the latter, I suspect.
(tags: rotherham abuse religion islam news multiculturalism)

Originally posted at Name and Nature. You can comment there. There are currently comments.
nameandnature: Giles from Buffy (Default)
Modern Microprocessors – A 90 Minute Guide!
Nice article about how modern microprocessors work.
(tags: microprocessor cpu hardware memory cache)
The Aural Majority: Do You Want to Swing, Virginia?
What makes music swing? With sound samples.
(tags: swing music shuffle rhythm)
Our quantum reality problem – Adrian Kent – Aeon
An article about quantum theory and the philosophy of science.
(tags: physics quantum research philosophy science everrett)
Printable True Bugs Wait Posters | natashenka
Abstain from strcpy! Wait for the string handling functions which are right for you.
(tags: programming funny security bugs C stdlib)

Originally posted at Name and Nature. You can comment there. There are currently comments.
nameandnature: Giles from Buffy (river brain)
Here's a C language technique which I'd not seen before starting my current job, which I think deserves to be better known.

Let's say you have a bunch of things, to which you've given sequential integer IDs using an enum.
enum my_things {
   thing_this,
   thing_that,
   thing_other,
   num_things
};

For each of those things, you want to store some other information in various arrays, and index into the array using the enumerated value to pull that information out. Examples might be a parser (where the enums might identify operators, and an array might contain pointers to functions to implement them) or a message handling system (where the enums might identify types of message, and the array might contain pointers to functions to handle the messages).
void (*thing_fns[num_things])(void) = {
   do_this,
   do_that,
   do_other
};

void do_thing(enum my_things current_thing)
{
    thing_fns[current_thing]();
}

void do_this(void)
{
    /* wibble */
}
/* etc, etc. */

The problem comes when you want to add a new thing. You're sizing the array using the enum, so it's hard to get that wrong. But if you have a lot of things, sooner or later someone will add a new my_things member to the middle of the list (perhaps you're listing your things in some order which makes sense in the context), go to update thing_fns, miscount how far down the definition thing_fns they've gone and screw up the ordering of the function pointers. Now the wrong function handles some (but not all) of the things, with hilarious results.

The solution is to maintain a single list of your things, and transform it into definitions for the enum and the associated arrays. You don't need to write fancy code generator scripts for this, you can use the pre-processor. Wikipedia explains how.

(Note that Wikipedia's example does away with sizing the array using the enum. They need to have a final NULL entry with no comma on the end to keep the compiler happy, so they'd end up writing the clunky num_things + 1. Now their array is sized correctly anyway.)

This chap goes into it in more detail, and also illustrates that your list of things doesn't have to be in a seperate file.

Re-writing my example to use X-macros is left as an exercise for the reader. :-)

Edited To Add: [livejournal.com profile] gjm11 points out that two of his friends have posted about this recently. [livejournal.com profile] gareth_rees has a more detailed example and some discussion.

Profile

nameandnature: Giles from Buffy (Default)
nameandnature

December 2025

S M T W T F S
 123456
78910111213
14151617181920
2122 2324252627
28293031   

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 8th, 2026 02:26 pm
Powered by Dreamwidth Studios