Tag Archives: C

Pitfalls in negative indexing in C

Negative indexing in C, such as a[-1], is legit, although rarely used. There are reasons (pitfalls) why negative indexing is not recommended. This post discusses these pitfalls when using negative indexing (for fun). 1. Negative indexing within the bound In … Continue reading

Posted in Programming | Tagged , | Leave a comment

Retrieve PID from the packet in Unix domain socket – a complete use case for recvmsg()/sendmsg()

The original question was how to retrieve the PID of the packet (sender) in the Unix domain socket. As titled, the answer is recvmsg()/sendmsg(). However, the most useful information I could find online is Michael’s man7.org. People keep talking about … Continue reading

Posted in OS, Programming | Tagged , , , , , , | 1 Comment

A paper review – seL4: Formal Verification of an OS kernel

Paper review for – seL4: Formal Verification of an OS Kernel daveti@cs.uoregon.edu Dec 10, 2013 How could we guarantee the code we are running is right? Even after different and long-time testing, we have yet not been so sure that … Continue reading

Posted in Embedded System, OS, Programming, Security | Tagged , , , , | Leave a comment

cgpic – Calling GProlog in C

Prolog is a straight-forward way to implement simple logic rules and do the query of the system. GProlog(gprolog) is the GNU version of Prolog implementation. To leverage the power of gprolog into our system code (C/C++), there are usually 2 … Continue reading

Posted in AI/ML, Programming | Tagged , , | Leave a comment

timer queue – a way to handle multiple timers using one thread

This post introduces a general way to handle multiple timers using one thread using C. K.R.K.C. -daveti 1. what is timer? The essence of timer is eventually a thread (either Python or Java threads are actually mapped and executed as … Continue reading

Posted in Programming | Tagged , , , | 3 Comments

Use POSIX regex in C

There is no standard regex lib in glibc. However, almost all UNIXs, Linux and even Mac OS should support POSIX regex, which provides a way to do regex processing in C. Below is the real example under Linux. For Mac … Continue reading

Posted in Programming | Tagged , , | Leave a comment

side effect of “++” in C – compiler implemenation with assembly

This post shows a common known side effect of “++” operator in C programming because of different compiler implementation. Assembly code from PowerPC and x86 with gcc is provide to show the key difference and the reason why for this … Continue reading

Posted in Programming, Stuff about Compiler | Tagged , , , | Leave a comment