Skip to content

Instantly share code, notes, and snippets.

View itczl22's full-sized avatar
👏
listening

itczl22

👏
listening
View GitHub Profile
@itczl22
itczl22 / big-little-endian.c
Last active October 30, 2016 08:11
大端小端存储
#include <stdio.h>
int main(void) {
// 储存方式的判断
unsigned int a = 0x12345678;
const char* buf = (char*)&a;
printf("%x\n%x\n", buf[0], buf[3]);
// 78 12, 所以是小端存储
const char* str = "12345678";
@itczl22
itczl22 / align-fill_out.c
Last active October 30, 2016 08:10
地址的对齐补齐
#include<stdio.h>
int main() {
char ch = 8; // 1 + 3
int it = 9; // 4 + 4
int* ptr = &it; // 8
printf("%p\n%p\n%p\n\n", &ch, &it, &ptr);
typedef struct {
short sit; // 2 + 6
@itczl22
itczl22 / variable-argument.c
Created October 30, 2016 08:08
c语言变长参数
/*
* 通过3个宏和一个类型实现:
* va_start va_arg va_end va_list
* 实现:
* 把参数在栈中的地址记录到va_list中, 通过一个确定参数first_num确定地址然后逐个读取值
* 通常也会在对第一个参数进行一些特殊处理以方便函数的实现
* 比如强制指定为参数个数、指定结束参数或者像printf一样使用格式占位符来
* 参数是如何获取的, 为什么要指定第一个参数:
* 函数的调用的参数会进行压栈处理, 而对参数的压栈是从右到左进行压栈
* 因此栈顶就是第一个有名参数, 而参数和参数之间存放是连续的
@itczl22
itczl22 / go-cmd-install.sh
Created July 4, 2016 05:09
Install Go and common cmd tools.
#!/bin/bash
TMP=`pwd`/go-cmd-`date +%s`
GOX=src/golang.org/x
mkdir -p $TMP/$GOX
cd $TMP/$GOX
git clone https://github.com/golang/tools.git
git clone https://github.com/golang/net.git