Makefile
基本格式:
target(目标):dependency(依赖)
(Tab字符) command
具体规则:隐含规则、定义规则、指令、注释
例: Target = hello $(Target) : $(Object)
Object = hello.o (print.0) (Tab字符) gcc $ (Object) -o- $(Target)
hello: hello.o rm * .o hello
(Tab字符) gcc hello.o -o hello make clean
hello.o : hello.c
(Tab字符) gcc -c hello.c -o hello.o
gdb调试
gcc test.c -o test -g 要加上-g才能进入gdb调试
gdb test
l: list 显示10行
b: break 设置断点 b 17 在第17行设置断点 b main 在main函数设置断点
info : 查看断点信息
run : 运行
print : 查看变量的值
c : continue 继续运行
n : next 下一步,不进入函数
step : 下一步,进入函数
return : 返回
q : 退出
Shell
命令解析器 指令->机器可执行
后缀 .sh 执行 ./_.sh 变量
#!/bin/(ba)sh
echo "first $1" 打印第一个变量
echo "second $2"
echo "third $3"
echo "all $*" 打印所有变量
echo "sum %#" 打印变量个数
#!/bin/sh
for dir in $1 $2 $3 $4 $5
do
mkdir $dir
cd $dir
touch $dir
echo "hello $dir" > $dir
cd ..
done
创建5个文件夹,并在里面创建一个同名的文件,每个文件显示hello文件名
#!/bin/bash 判断类型
PATH = $ 1
if [ -Z $PATH ]; then 判断是否为空
echo "ERROR"
exit
fi
if [ -d $PATH ]; then 判断是否为目录
echo "DIR"
elif [ -f $PATH ]; then 判断是否为文件
echo "FILE"
fi
#!/bin/bash
read key 从键盘读
case "${key}" in
[A-Z] ) echo "Upperletter";; 大写字母
[a-z] ) echo "Lowerletter";; 小写字母
[0-9] ) echo "Number" ;; 数字
* ) echo "ERROR";; 其他
esac
#!/bin/bash #!/bin/sh
file = "hello.c" cat > $file << EOF
target ="hello" #include<stdio.h>
echo "#include<stdio.h>" > $file int main()
echo "int main()" >>$file {
echo "{" >>$file printf("helloworld!\n");
echo 'printf("helloworld!\n");' >> $file }
echo "return 0;" >> $file EOF
echo "}" >> $file
数据类型
字节数
int 4 short 2 long 4 float 4 double 8 char 1
注意 : sizeof是关键字,不是函数
man 3 strlen 可以查看strlen的头文件
const 修饰只读变量
不能通过变量的值去修改对应内存里的数据
可以通过其他方式修改
volatile防止编译的时候被优化
逗号表达式中,最后有个表达式的值是最终值
++i --i : 在执行i所在的语句之前对i加/减1
i++ i-- :在执行i所在的语句之后对i加/减1
a+=a 表示 a=a+a
int a=4 int a=4 int a=4
a+=a++; a=9 a+=++a; a=10 ++a+=a; a=10
int a=4 int a=4
++a+=a++; a=11 ++a+=++a; a=12