Skip to content

Instantly share code, notes, and snippets.

Gcc Preprocessor Options

-I dir

Add the directory dir to the list of directories to be searched for header files. Directories named by -I are searched before the standard system include directories. If the directory dir is a standard system include directory, the option is ignored to ensure that the default search order for system directories and the special treatment of system headers are not defeated . If dir begins with =, then the = will be replaced by the sysroot prefix; see --sysroot and -isysroot.

@hello009-commits
hello009-commits / 459.md
Created May 19, 2013 08:59
aligned memory allocation

NAME

posix_memalign -- aligned memory allocation

SYNOPSIS

#include <stdlib.h>

int posix_memalign(void **memptr, size_t alignment, size_t size);

@hello009-commits
hello009-commits / 451.md
Last active January 3, 2023 12:45
c语言中struct的内存对齐

c语言中struct的内存对齐

为了让CPU能够更舒服地访问到变量,struct中的各成员变量的存储地址有一套对齐的机制。这个机制概括起来有两点:第一,每个成员变量的首地址,必须是它的类型的对齐值的整数倍,如果不满足,它与前一个成员变量之间要填充(padding)一些无意义的字节来满足;第二,整个struct的大小,必须是该struct中所有成员的类型中对齐值最大者的整数倍,如果不满足,在最后一个成员后面填充。

各种类型的变量的align值如下,参考的是wikipedia的页面:Data structure alignment

The following typical alignments are valid for compilers from Microsoft, Borland, and GNU when compiling for 32-bit x86:
@hello009-commits
hello009-commits / gist:5607012
Last active December 17, 2015 12:08
c const static keywords

size_t

The C language provides the separate types size_t and ptrdiff_t to represent memory-related quantities. Existing types were deemed insufficient, because their size is defined according to the target processor's arithmetic capabilities, not the memory capabilities, such as available address space. Both of these types are defined in the stddef.h header (cstddef header in C++). size_t is used to represent the size of any object (including arrays) in the particular implementation. It is used as the return type of the sizeof operator. The maximum size of size_t is provided via SIZE_MAX, a macro constant which is defined in the stdint.h header (cstdint header in C++). It is guaranteed to be at least 65535. Note that size_t is unsigned, signed sizes can be represented by ssize_t.

getpid()

getpid, getppid -- get parent or calling process identification

@hello009-commits
hello009-commits / BeyesianAvg.py
Created September 6, 2012 08:32 — forked from lastland/BeyesianAvg.py
尝试用这篇post: http://www.matrix67.com/blog/archives/5044 中的方法实现的一个自动中文抽词算法的Python程序
# -*- coding=utf-8 -*-
import collections
# Usage:
# 我的做法是把WordsDetector.py里的结果输出到文件,
# 然后把文件名放到下面的names列表中,运行本程序。
names = ['name0',
'name1',
'name2',