Apprentiship blog

linking and refactoring

December 06, 2018

Most of todays activities where split between using the project template I wrote yesterday on today’s exercise from learn-c-the-hard-way which was about linking and dynamic libraries. It was interesting to see how a complied C program could take a library as an argument then call functions from the library. After that I decided to see if I could make use of the skeleton project from yesterdays exercise and that took some time to get working.

Initially I though it was the tests not running correctly but it turned out I was not calculating the lengths of strings correctly and should have used strlen instead. I just took a look at glibc’s version of strlen and some of it looks familiar like chunking string using duffs device’s, it’s much more extensive than what I wrote.

what i did

int string_length(const char * string)
{
  int i = 0;
  while(*(string++)) { i++; }
  return i;
}

Once I got that working as intended, I moved on to porting some of the solutions I have from advent of code from tddbin to a git repository, problem is I’ve deleted most of them so I took it as a chance to utilise some of the practices I’ve covered over the past day, which too longer than I thought it would mostly as I forgot the solutions.

Later on in the day there was a short unplanned mobbing session while we ( AnastasiaLewis and myself) tried to add the directory where ghc / haskell keeps executable files to the shell $PATH variable.


Written by Marc McIntosh Find him on github