添加 0.md

This commit is contained in:
rabix 2024-05-13 10:15:58 +08:00
parent 3114d18818
commit 2cb8f2361a
1 changed files with 23 additions and 0 deletions

23
0.md Normal file
View File

@ -0,0 +1,23 @@
# 观察
首先来看一段代码,这段代码可能和你平常写的也差不多,但是也有一些区别
<iframe width="800px" height="200px" src="https://godbolt.org/e?hideEditorToolbars=true#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:2,endLineNumber:8,positionColumn:2,positionLineNumber:8,selectionStartColumn:2,selectionStartLineNumber:8,startColumn:2,startLineNumber:8),source:'%23include+%3Cassert.h%3E%0A%0Aint+main(void)+%7B%0A++++int+a+%3D+3%3B%0A++++int+b+%3D+5%3B%0A++++%0A++++assert(a+%2B+b+%3D%3D+8)%3B%0A%7D'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:32.74151436031332,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:executor,i:(argsPanelShown:'1',compilationPanelShown:'0',compiler:cclang_trunk,compilerName:'',compilerOutShown:'0',execArgs:'',execStdin:'',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'',overrides:!(),runtimeTools:!(),source:1,stdinPanelShown:'1',wrap:'1'),l:'5',n:'0',o:'Executor+x86-64+clang+(trunk)+(C,+Editor+%231)',t:'0')),header:(),k:67.25848563968668,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4"></iframe>
编译运行它,结果是什么都没有,这说明没有问题,那么如果不小心打错了呢,比如你是复制粘贴的第四行只改了变量名
<iframe width="800px" height="200px" src="https://godbolt.org/e?hideEditorToolbars=true#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:14,endLineNumber:5,positionColumn:14,positionLineNumber:5,selectionStartColumn:14,selectionStartLineNumber:5,startColumn:14,startLineNumber:5),source:'%23include+%3Cassert.h%3E%0A%0Aint+main(void)+%7B%0A++++int+a+%3D+3%3B%0A++++int+b+%3D+3%3B%0A++++%0A++++assert(a+%2B+b+%3D%3D+8)%3B%0A%7D'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:32.74151436031332,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:executor,i:(argsPanelShown:'1',compilationPanelShown:'0',compiler:cclang_trunk,compilerName:'',compilerOutShown:'0',execArgs:'',execStdin:'',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'',overrides:!(),runtimeTools:!(),source:1,stdinPanelShown:'1',wrap:'1'),l:'5',n:'0',o:'Executor+x86-64+clang+(trunk)+(C,+Editor+%231)',t:'0')),header:(),k:67.25848563968668,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4"></iframe>
那么很快,当你运行时,程序就会提示你预先认为的`a + b == 8`并不成立,导致出错的代码是`/app/example.c`他的行数是`7`。
```
我们把 /app/example.c:7 叫位置信息
其中/app/example.c是文件名
7是行数
有了这两个就可以精确定位出问题的代码附近
```