Function calls in the C programming language make heavy use of the stack. When functions are called, they create a so-called stack of frames. This stack frame is used to allocate memory for local variables and intermediate values. The stack frame also contains the previous frame pointer and typically the link register. We’ll use an example in ARM Assembly to illustrate a function call and understand the stack of frames when C functions, how they translate to Assembly and what the stack is doing in an ARM processor.
In this post we can explore how to the
gcccompiler converts to C to ARM assembly language. We’ll specifically look at conditional logic. We’ll look at examples of
else, then end with a
switchstatement. To convert C to ARM assembly we will use the
-Sflag on GCC. All these examples were done on a Rapsberry Pi running Raspbian.
Timeline of Unix Command Line Tools by initial release date.
There are many scenarios where a delay line is needed in signal processing. Scenarios ranging from Digital Filters, Convolution, Reverberation, Echo and others. Delay lines have a fixed length of N samples. When delay lines take in a new sample they discard the oldest sample. In this post we discuss how delay lines work and implement a delay line in the C programming language.
Using a 2-wire serial connection we can communicate from a Rapsberry Pi (RPi) to an Arduino. For the Rasperry Pi we’ll use the built in UART accessed through a
tty, and the Arduino we’ll use the Serial Communication Library.
Daemons are long running processes that run in the background with no controlling terminal - tty. Use cases for daemons are when the program needs to be available at all times and managed by the scheduler. Popular examples are httpd, sshd, cron, inetd. All of these end in “d”, which is a convention for the name of a daemon. Daemons typically do not have the ability to write to
stderr, and have no means to connect to
stdinbecause they have no controlling terminal. Having no controlling terminal is a big deal in daemons. If they could connect to a controlling terminal they could be used in nefarious ways. We guarantee the daemon cannot take on a controlling terminal by doing the so-called “double fork”. Usually, output from the daemon is done by writing to log files. These logs are typically written in the in
/var/logdirectory. Input to a daemon, when necessary, is typically through sockets and signals. Let’s write an example daemon in C that runs on Unix.
In this post we’ll create an example client and server that communicate over UDP in C using Unix as the Operating System. UDP is a connectionless, unreliable datagram packet service. The term connectionless means there is no handshake between the client and server before information is exchanged. The term “fire and forget” applies here since the client sends and beforehand has no negotiation with the server. The term unreliable means there is no guarantee of delivery, ordering or duplicate protection. UDP is best for time-sensitive applications where it is preferable to discard packets rather than waiting for delayed ones.
Use the glibc
<dirent.h>to list all the files in a directory using the C programming language. The
scandirfunction allows for sorting, comparing and filtering the names of files in the directory. There are default options to list alphabetically through the
alphasort()glibc standard function.
A simple example that will parse JSON in C using Flex and Bison. Forewarning, while this example works well it’s not going to handle every JSON case. I’ll highlight the limitations of what cannot be parsed towards the end of the post.
This blog post attempts to list and describe the majority of Virtual Network Device types in Unix. Networking with Linux is a hot topic especially in the IoT and Datacenter areas. Read on and you’ll see a large array of Device Types found in Unix.
In this post we’ll use iproute2 to create tunnels between two unix hosts. This will be the simplest form of an IP-in-IP tunnel.
I have the situation where I need to compare packages, settings, configurations across multiple Linux distributions. Docker is a great tool to pull images from all of the linux distributions to compare and contrast nearly anything you can think of. In this post we’ll create a simple docker compose file and run containers from the centos, alpine, ubuntu, archlinux, busybox and debian images.
In this blog post we will construe some simple examples of regular expressions in C, also known as a
regex. We will use the popular libraries PCRE and PCRE2. If you don’t know what a regex is or have never used them, then you can close this tab right now! Learning regular expressions in in C is probably the wrong way to go. Start with something more easy like Python, Perl, or anything else because doing them in C is difficult. If you know regular expressions from other languages, learning them in C will strengthen your understanding of the concept. This example is meant to be easy to understand, simple and useful.
I needed an HTML
selectfor every Timezone and really couldn’t find what I was looking for. Here is an abbreviated version so you know what I’m talking about:
I wanted to use Apache Lucene to search User Names. It’s definitely not straightforward. This post explains how to do it by defining our own custom
Analyzerand explaining how we form the
Document, index the user names and query with a
Have you ever needed to format some gnarly JSON that is unreadable and/or too large to look through? It’s super easy to format it with
vim. We can use the popular
jqtool - link at the end of this blog post.
staticvariable in C is unnecessarily confusing because it is used for both the memory management model and for linkage. Since these two concerns are mutually exclusive another keyword would have really cleared things up in the linkage case.
Implementing FIR filters in C is much easier if we make use of the static variables declared in our functions. In this blog post we will create some simple example FIR filters, and get their impulse response. To understand this post you will have to have the basic theory of FIR filtering down.
A Barrier in computing is a synchronization method where a group of threads cannot proceed until a condition allows the blocked threads to proceed. In this post we will construe an example of a Barrier that relates to men and women at the dinner table using pthreads. We will have a bunch of men waiting to get their food, but the men will be blocked until the woman has eaten, thus, trigger the start state of the Barrier.
In this post we’ll provide a simple Fast Fourier Transform (FFT) example in C where we will sacrifice performance and external code dependencies for readability and simplicity. After understanding this simple FFT example it should trivial to modify for performance and adaptations for computer architecture. Please note this has been run on an Arduino and the performance is sub-par. I’d say this FFT implementation is probably best suited for a microcontroller.
If you’re looking to replicate the pbcopy and pbpaste commands in WSL then you’ve found the right place! In this post we will make some simple shell scripts to replicate pbcopy and pbpaste in OS X. If you’re accustomed to pbcopy/pbpaste in Mac OS X, it’s hard to not have the equivalent in WSL. One spoiler alert the commands just are not as fast as they are in OS X.
In this post we will create a useful Linked List in the C Programming Language. This is opposed to all the useless linked lists that I’ve seen on the internet. They are numerious, typically written by academics that haven’t much experience programming. It’s not the logic or syntax that is bad, but the API and functions they create that make the usage of the Linked List obtuse and awkward. This implementation of a Linked List in C is something meant to be used over and over again in projects.
The Internet is the most complex public service ever created! The Internet is truly amazing. Want to know how the Internet works? If you come from a Computer Science Background it’s very unlikely you will know about how the internet works. If you take Cisco Certifications or do Networking, it is also very unlikely you understand how the Internet works. Recently, I couldn’t resist and I learned how the internet works. In this Blog post I want to show you how I learned how the Internet works.
In the world of software these days it is expected that applications do multiple things at once. With that said it’s pretty typical that multiple processes or threads have read and write access to a database. In this post we will go over transactions in SQLite which prohibits changes made to the database unless they are inside a transaction.
Let’s add SQLite to your C project. It’s easy and straightforward. We’ll use the SQLite.org recommended way by adding the so-called “amalgamation” to our C project and compile from source. In the words of SQLite.org “the use of the amalgamation is recommended for all applications.” In this blog post we’ll download, compile and use SQLite in our C project.
Some services don’t support CORS, but we can use NGINX to make CORS supported with this simple hack! To enable CORS on any service we need to have NGINX configured as a Reverse Proxy and have NGINX add a successful pre-flight response to the CORS pre-flight request. Read on to get this simple example to work.
Let’s create a basic Flex/Bison Project with Autotools. The GNU Documentation for Automake specifies Flex/Bison Support. We will take it a step further and provide a complete example with a Flex Scanner and Bison parser.
Copy and Paste doesn’t work in neovim because it cannot access the System Clipboard on WSL - Windows Subsystem Linux. This simple small hack solves this issue. Let’s start with a little background so this all makes sense. This all works without having to install X Windows or any other tools.
This post has a simple bash script to create a basic Hello World autotools project with a single command. The justification for this autotools script is I’ve not seen a consolidated script that keeps it simple in one place. The script creates a boiler plate autotools hello world project. Here is what it does:
Let’s discuss how to pass data from a C program to a Python Script and vice-versa, how to pass data between a Python Script and C program. As with most things in software; there are a LOT of ways to do this. In this blog post we’ll discuss the more exotic Unix domain datagram socket. Specifically, this is domain
SOCK_DGRAMtype of socket. Before you consider this method let’s address some of it’s benefits/limitations:
How are double pointers used in C?
In this blog post we talk about Double Pointers in C. Also, known as a pointer to a pointer. We go over 3 use cases to fully understand the usage and go in-depth into a use case where a function can allocate memory for the caller.
Don’t Listen to the Autotools Haters
Being an avid C and Unix Geek, I decided to ignore all the hate out there about GNU Autotools and try it for myself. For those of you that don’t know the GNU Autotools suite consists of Autoconf, Automake and Libtool. You’ll see some major criticisms out there from people saying it’s way too complex, challenging, hard to use as well as all sorts of other criticisms. Let’s face it though, build systems are complex. I’ve used all sorts of them. Communities love to re-invent the wheel and build their own tool but at the end of the day to support everything is a massive endeavor.
Updated Feb 7, 2020
Imagine a scenario where you have N threads and can only do something when M of them are ready. Java already has this built in since 1.5 with the CyclicBarrier.
Any program these days that does any significant computational load should utilize the availble processor cores. In this post we’ll show an example using Java where we schedule Callables on all available processor cores. In Java a Callable is task that returns a result and may throw an exception. It is very similar to a Thread, but gives a much easier way to return the result asynchronous computation. I typically don’t see many reasons to not use Callables over Threads, since even if you don’t want or need to return the result you can still return some sort of status code. This blurb is directly from the Javadoc The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.
When getting started on the SQLite C API they recommend 2 basic ways:
sqlite3_get_table()both are convenience wrappers around the core API Calls. They give good examples for the
sqlite3_exec()call, and the
sqlite3_get_table()is deprecated in the documentation. Using
sqlite3_exec()employs a callback function which gives the advantage of speed and low memory usage - due to being able to process each row at a time. It however, does not allow for knowing when all the rows are returned, as well as, being synchronous.
Updated Feb 7, 2020 and April 3, 2020
Using NGINX as a front-end server to forward to multiple back-end services works great by configuring NGINX as a reverse proxy. The reverse proxy configuration will have NGINX serve HTTP/HTTPS URLs and forward them to them to network addresses such as a database listening on HTTP at a specific port, API servers, static websites, etc. Basically we can turn NGINX into an HTTP router. NGINX is also a great front man for back-end services such as HTTPS and HTTP/2. For instance if you had a Database, API Server and static site you could have an SSL certificate just for NGINX and they would all be behind HTTPS and the reverse proxy would convert the HTTPS and send HTTP. That’s a post for another time however.
I’ve built a little PSK31 convolutional encoder and decoder and originally wanted to make a graph showing the error correction capabilities as a function of encoder output length and number of bit errors into the decoder. Making a long story short; I couldn’t devise a good method of creating this graph and stuck to hand making error cases to see the performance of the decoder. Note, the quantization for both the encoder and decoder are hard metrics using the Hamming Distance which doesn’t perform as good as soft metrics. First, let’s define the convolution encoder input and output.
What are the similarities and differences between spoken languages and programming languages?
A little side project - that actually turned in to a larger project is an implementation of the PSK31 Specification. I’m hoping to create an Open Source Project likely called
OpenPSK31or something similar. This specification could use some improvements with all the advancements we have in computational power and software over years since the specification was created in 1998. I’ve created a place on this site for PSK31 to document the project I’ve done. Not all the content is there yet, but I’ll be blogging about the updates as they come in. A fully working PSK31 system has a lot of moving parts and I hope to power through and get something that can both send and receive PSK31. The focus will be on the QPSK31 part of the specification so the convolutional encoding and decoding is used to correct bit errors.
Hello All! This is the first time I’ve tried blogging. I “do” IT for a living and am involved in all sorts of Software. I’m usually tinkering around doing technical projects with software and hardware so I figure I’d blog about it. Mostly to just blog on what I’ve been doing, hopefully I’ll get a good discussion going and maybe help someone along the way. There are a couple of Open Source projects I’d like to get kicked off. We’ll see where it goes …
subscribe via RSS