Category Archives - C

Consolidating String Constants Among C++, Objective-C++ and Swift

June 18, 2017 12 Comments

I’m back to writing a synth audio unit. The Apple Example AudioUnit(s) Code is good, but one thing that bothers me about it is how many bare string constants there are.
I put up

Nested withUnsafeMutablePointer()

November 22, 2016 12 Comments

Since withUnsafeMutablePointers() has gone away, I typed out this example of using nested withUnsafeMutablePointer() so I was sure I knew what I was doing:

var int1 = UInt32(1)
var bytes1 = [UInt8(1), UInt8(2), UInt8(3)]

C and Swift – strcpy

February 27, 2016 12 Comments

Below are some of the things I’ve needed to do recently, when interfacing with C code. Maybe these will be useful to someone. I’m trying to implement Unix-domain sockets in Swift, and it’s been kind

PThreads in Swift

February 20, 2016 12 Comments

Here’s some code that implements pthreads via swift.

class PTTask {
init () {
func run() -> Int32 {
let threadPtr = UnsafeMutablePointer.alloc(1)
let selfPtr = UnsafeMutablePointer.alloc(1)
selfPtr.memory = self
let attrPtr

Signal Handling with Swift – sigaction version

February 20, 2016 12 Comments

I need a pointer in my signal handler, so I need to use sigaction. The following doesn’t go quite all the way with this, but I think it’s a useful example.

func shandler(sig: Int32,

Signal Handling with Swift (1st Attempt)

February 18, 2016 12 Comments

I need a high precision timer queue. I’m looking at standard *nix ways of implementing some of this – setitimer in particular. In preparation I wrote a very simple console swift app to test out