Below you will find pages that utilize the taxonomy term āCā
Limit String Length in Printf in C
I can’t believe how many times I forget this trick! so I am writing it down so I won’t forget it!
Normally when you use printf function with “%s” formatting to print a string (char *) you rely on C convention of terminating a string with a NULL character (i.e. value 0).
So if you want to print small part of longer string, you copy the part you need to a new buffer and terminate it will NULL.
My First Makefile
The following is a sample Makefile for simple project, here I am building a simple “Bloom Filter” library, and “main” program to use it.
The library will have the following files:
- hash.h and hash.c
- bloom.h and bloom.c
and we should get “libbloom.a” out of it.
The “main” program will use:
- main.c
- bloom.h
- libbloom.a
and we should get “main” executable. So our make file should look like this:
$ cat Makefile
CFLAGS=-Wall -O3
LDFLAGS= -L.
LDLIBS=-lbloom
CFLAGS += `pkg-config --cflags libpcre`
LDFLAGS += `pkg-config --libs libpcre`
OBJS=main.o other.o libbloom.a
BLOOM_OBJS=hash.o bloom.o
all: main libbloom.a
main: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
libbloom.a: $(BLOOM_OBJS)
ar rcs $@ $^
.PHONY: clean
clean:
-rm main libbloom.a *.o
Makefile use TAB not spaces for indentation.
Loop Unwinding Experiment
Few months ago I read an interesting post by Mike Haertel the original author of GNU grep titled “why GNU grep is fast“, one of the reason given is loop unrolling.
Few weeks ago I came a cross the same post which made me more interested on Loop Unrolling, so I decided to experiment with it, I implemented simple function to search for an item inside a list of items, and return as soon as it finds it, soo here is my result: