Error handling and resource management are pervasive in programs. RAII originated in C++ is great. With RAII, it is much easier to write easy-to-read code that allocats/deallocats resources in the constructor/destructors. By representing a resource with a local object, we are sure that local object’s destructor will release the resource and will not forget to
Read more
Category: Programming
Tutorials and tips on programming related to Linux systems, Web and more.
Statically Linking C and C++ Programs on Linux with gcc
Posted onBefore statically linking you C and C++ programs, you should be aware of the drawbacks of the static linking especially with glibc. There are some good discussions already: with glibc you’re linking static programs which are not really static and some others here and here. That said, you can choose to statically link C and
Read more
Auto Indenting for OCaml Code in Vim with ocp-indent
Posted onThe built-in indenting in Vim for OCaml seems not very good. How to set up auto indenting for OCaml code in Vim? ocp-indent works very well for me. This posts introduces how to configure Vim to use ocp-indent to automatically indent/format OCaml code. First, install ocp-indent after installing opam: $ opam install ocp-indent Second, configure
Read more
Linux UDP Programming Tutorial
Posted onUDP has its advantages over TCP, such as being relatively lightweight and receiving one packet per read call (recvmsg), although the programmers need to handle related issues, such as packet lost and out-of-order packets delivery. This post gives information and references on how to write UDP programs in a C/Linux environment. What is UDP Check
Read more
How to Measure Time Accurately in Programs
Posted onIt is quite common to measure the time in programs using APIs like clock() and gettimeofday(). We may also want to measure the time “accurately” for certain purposes, such as measuring a small piece of code’s execution time for performance analysis, or measuring the time in time-sensitive game software. It is hard to measure the
Read more
ASCII Table and ASCII Code
Posted onThis post gives the ASCII table and ASCII code with ASCII control characters and ASCII printable characters and a tool to convert ASCII codes to ASCII characters. Introduction to ASCII table and ASCII code ASCII stands for American Standard Code for Information Interchange. An ASCII code is the numerical representation of a character since computers
Read more
C++ Reference and Styles
Posted onC++ References Reference of the C++ Language Library, with detailed descriptions of its elements and examples on how to use its functions: http://www.cplusplus.com/reference/ C++ reference: http://www.cppreference.com/w/ C++ Styles I compile a list of C++ styles on the Internet. http://geosoft.no/development/cppstyle.html http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml http://www.mactech.com/articles/develop/issue_02/C%2B%2B_Style_Guide_v007.html http://www.cs.uga.edu/~dkl/1302/Fall99/style.html
Java与C++在语言方面上的不同
Posted on1,Java抛弃了头文件、预处理机制、goto语句和多维数组。 2,Java不支持指针。 3,Java抛弃了联合体和结构体。 4,Java不支持独立函数。所有函数必须在类中声明。 5,Java不支持多重继承,可以使用接口模拟多重继承。 6,Java不支持运算符重载。 7,Java中布尔型不再用整数来代替。 8,Java中主函数必须有一个字符串类型的参数。 Java抛弃的C++中的这些机制和结构多数都是“危险”的,减少了语言的复杂性,增强了安全性,虽然在一定程度上减少了其灵活性。
Makefile Tutorials
Posted onMake is a utility that automatically builds executable programs and libraries from source code by reading files called makefiles which specify how to derive the target program. Make is widely used, especially in Unix/Linux world. More introductions to Make and it’s history can be found on Wikipedia. In this post, I list articles for Makefile
Read more
Hashing Library for C
Posted onI try to find some Hashing libraries for C and find several good ones. The hsearch function in the GNU C library. There are other methods to organize information which later should be searched. The costs of insert, delete and search differ. One possible implementation is using hashing tables. The following functions are declared in
Read more
x86-64 ISA / Assembly Programming References
Posted onThis post collect the reference resource for x86-64 (also know as Intel 64, AMD 64) ISA / assembly language programming. x86-64 is a 64-bit extension of the Intel x86 instruction set. ==x86-64 Assembly Programming== Introduction to Computer Systems Resources (15-213 Introduction to Computer Systems Resources from CMU) Lots materials for learning machine-level programming on the
Read more
Inline Assembly with GCC on Linux
Posted onOne cool feature of gcc is that it can inline assembly into C code. With inline assembly, the programmer can precisely control the execution of the processor, such as forcing variables to use registers, getting special processor state efficiently, and writing critical efficient code in assembly by hand. I compile a list of tutorials from
Read more
GNU C Reference Manual
Posted onWhen we program in C, a C reference by hand is usually useful. The GNU C Reference Manual provides us a good reference for the C programming language implemented by the GNU C Compiler. “This manual is strictly a reference, not a tutorial. Its aim is to cover every linguistic construct in GNU C.” GNU
Read more
The C Programming Style that I Follow
Posted onC programming language allow any style the programmer like. A good style can make the code easy to understand and maintain, while a bad style will make the project a nightmare. This is the C programming styles that I follows: 1. For each source file (*.c), there is a header file (*.h) that have the
Read more
Vim Indenting C/C++ Code
Posted onVim provides some basic formatting commands. A combination of these commands with the editing commands will make the programmer happy. A list of basic text formatting commands in Vim: = is an operator that formats/indents text. i{ is a text object that specifies the surrounding code block. It should be used together with v, =,
Read more
fclose – Close a Stream
Posted onfclose is a frequently used C standard library which closes the file associated with the stream and disassociates it. NAME fclose – close a stream SYNOPSIS #include <stdio.h> int fclose(FILE *fp); DESCRIPTION The fclose() function will flushes the stream pointed to by fp (writing any buffered output data using fflush()) and closes the underlying file
Read more
GDB Cheat Sheet
Posted onHere is a collection of good GDB Cheat Sheets from the Internet. GDB QUICK REFERENCE GDB Version 5 GDB Cheat Sheet gdb Cheatsheet GDB commands by function – simple guide
GNU glibc Manual
Posted on“The C language provides no built-in facilities for performing such common operations as input/output, memory management, string manipulation, and the like. Instead, these facilities are defined in a standard library, which you compile and link with your programs. The GNU C library, described in this document, defines all of the library functions that are specified
Read more
Vim + cgdb
Posted onI begin to use vim for programming. I like the tools that focus on one function. I used to use emacs. But I think I like vim more. For debugging, I use gdb. But I use the front end cgdb. I can see the codes with the cursor when debugging. I can use F8 for
Read more
Win32 Programming: Operation on Files
Posted onHere, we show some example code on Win32. The code are operations on file on Win32 OSes. The code here uses some MFC classes. Recursively show the files from a path: void Show(const char *folderPath) { CFileFind finder; CString path(folderPath); path += “*.*”; BOOL bWorking = finder.FindFile(path); while (bWorking) { bWorking = finder.FindNextFile(); cout <<
Read more