(5.4.1)--5.4TheUsageofgcc.ppt

上传人:刘静 文档编号:84315678 上传时间:2023-04-04 格式:PPT 页数:13 大小:933.59KB
返回 下载 相关 举报
(5.4.1)--5.4TheUsageofgcc.ppt_第1页
第1页 / 共13页
(5.4.1)--5.4TheUsageofgcc.ppt_第2页
第2页 / 共13页
点击查看更多>>
资源描述

《(5.4.1)--5.4TheUsageofgcc.ppt》由会员分享,可在线阅读,更多相关《(5.4.1)--5.4TheUsageofgcc.ppt(13页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、TheUsageofgccTheUsageofgccgcc v check the version number of gccgcc f1.c o f2(gcc f1.c)Example:#include int main()printf(hello worldn);return 0;The usage of gcchello.cCompile the program of multiple source files by gcc/mul1.c#include#include“my.h”main()printf(hello worldn);f();/mul2.c#include f()prin

2、tf(“in f()n”);/my.hvoid f();laidell lai gcc mul1.c mul2.c o m.outmul1.c/mul2.c/my.hCompile the program of multiple source files by gcc/mul1.c#include#include“my.h”main()printf(hello worldn);f();/mul2.c#include f()printf(“in f()n”);/my.hvoid f();laidell lai gcc mul1.c mul2.c o m.outThe defect of taki

3、ng gcc to compile the program of multiple source files:Every file must be recompiled.gcc contains complete functions of error checking and warning prompt to help programmers find error codes as soon as possible.gcc includes more than 30 warnings and three warning levels.Warning prompt of gccA bad ex

4、ampleThe main function doesnt use the return statement to return an int type value.Variable var is defined but not used.#include void main(void)long long int var=3;printf(this is not a standard c program!n);bad.cgcc-Wallbad.cWarning options of gccoptioinsoptioinsfunctionsfunctions-Wcomment-WcommentW

5、arnWarningingifcommentnestingoccurs(/*appearsafter/*)ifcommentnestingoccurs(/*appearsafter/*).-Wformat-WformatWarnWarningingiftheiftheparameterparameterpassedtopassedto printfdoesnprintfdoesn tmatchthespecifiedformattmatchthespecifiedformat.-Wmain-WmainWarnWarningingifthereturnifthereturntypetype of

6、mainisnotofmainisnotintintortheparametersareincorrectwhencallingmainortheparametersareincorrectwhencallingmain.-Wparentheses-WparenthesesBasedonthecontextinference,Basedonthecontextinference,warningwarningifif(n=10)n=10)iswritteniswrittenasas(n=10)(n=10).-Wswitch-WswitchWarnWarningingifoneormorecase

7、branchesaremissingfromtheswitch(onlyapplicabletoenum)ifoneormorecasebranchesaremissingfromtheswitch(onlyapplicabletoenum).-Wunused-WunusedWarningiftWarningifthevariableisdeclaredbutnotused,orthestatictypefunctionisnotcalledhevariableisdeclaredbutnotused,orthestatictypefunctionisnotcalled.-Wuninitial

8、ized-WuninitializedWarningiftheautomaticvariableusedisnotinitializedWarningiftheautomaticvariableusedisnotinitialized.-Wundef-WundefWarnWarningingifundefinedvariablesareusedinthe#ififundefinedvariablesareusedinthe#ifmacromacrofordecision.fordecision.-Winline-WinlineWarningifthefunctioncannotbeinline

9、dWarningifthefunctioncannotbeinlined.-Wmissing-declarations-Wmissing-declarationsWarnWarningingifaglobalfunctionisdefinedbutnotdeclaredinanyheaderfileifaglobalfunctionisdefinedbutnotdeclaredinanyheaderfile.-Wlong-long-Wlong-longWarningiflonglongtypeisusedWarningiflonglongtypeisused.-Werror-WerrorTur

10、nallwarningsintoerrorsTurnallwarningsintoerrors.Function library:header file(.h)+library file(.so,.a)The default paths that can be identified by the system:header file:/usr/includelibrary file:/usr/libAccessing a file in a non-default path must specify the path while compiling.header file-Ilibrary f

11、ile-LThe library dependency of gccgcc k.c I /home/lai/include o kgcc k.c L /home/lai/lib lkk o kAccessing a file in a non-default path must specify the path while compiling.header file-Ilibrary file-L,the parameter after-l indicates that the library libkk.so is to be found.The library dependency of

12、gccCode optimization refers to that the compiler can find out the part which is not fully optimized by analyzing the source code and recombine the code to improve the execution performance of the program.gcc implements code optimization by option-On.-O,-O1:they refer to reducing the length and execu

13、tion time of code at the same time.-O2:it contains all the functions of-O and can perform the work of instruction scheduling.-O3:it contains all the functions of-O2 and can perform some optimization work of loop unrolling.Optimization options of gccA code optimization example#includeintmain()doublec

14、ounter;doubleresult;doubletemp;for(counter=0;for(counter=0;counter400counter4000 0.0*4000.0*4000.0/20.0+2030;.0*4000.0*4000.0/20.0+2030;counter+=(5-3+2+1)/4counter+=(5-3+2+1)/4)temp=counter/1239;temp=counter/1239;result=counter;result=counter;printf(theresultis%1fn,result);return0;optimeze.cUse the following options to compile the program.Execute the program,find its execution time,and observe the difference.time./a.outExample:optimize.cgcc optimize.c gcc O optimize.c EmbeddedSoftwareDesignEmbeddedSoftwareDesign

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com