gcc简单使用

来源:互联网 发布:工具书阅读软件 编辑:程序博客网 时间:2024/06/02 07:31

1.进入x-shell,手动连接公司linux服务器,telnet 10.2.10.100,然后输入用户名和密码

2.进入shell之后,进入到自己的共享文件夹

3.进入vi界面,编写一个简单的hello world程序:

#include<stdio.h>

 int main()

{

     printf(“hello world ,hello xiongmai”);

     return 0;

}

4.进入底端模式,保存文件并推出vi

5.在终端中输入$ gcc a.c,然后在用ls展示当前文件夹内容可以清楚的发现,出现了一个 a.out的文件

6.运行出现的程序,运行代码 为 ./a.out (./代表当前目录,../代表上一级目录)

 

 

接下来使用的时gcc警告提示功能:

1.编写一个让人产生警告的代码,取名warning_code.c

其代码如下:

#include<stdio.h>

void main()

{

    long long int var=2010;

    printf("let's look,the warning code");

}

2.使用命令:

gcc –pedantic warning_code.c –o warning_code

3.毫无疑问,这个糟糕的代码开始报错

 

值得注意的是-pedantic编译选项并不能保证被编译程序与ANSI/ISOc标准的完全兼容,只能让这个目标越来越近。

-o filename可以指定输出文件名,若没有指定的话,默认文件名为a.out

 

 

Gcc的优化功能:

只是做了简单的尝试。

1. 输入一下简单代码

#include<stdio.h>

int main()

{

    unsigned long int computer;

    unsigned long int result;

    unsigned long int temp;

    unsigned int five;

    int i;

    for(computer=0;computer <2009*2009*100/4 +2010 ;computer +=(10-6)/4)

    {

          temp=computer /1979;

    for (i=0;i<20;i++)

         {

              five=200*200/8000; 

         }

         result =computer;

    }

    printf("result is %d\n ",result);

    return 0;

}

 

2.输入代码之后执行命令

Gcc _ine.c –o _ine

代码编译完成之后输入计算时间的代码:

# time ./_ine,没错时间就这么被计算出来了:

 

2. 直接进行-O3优化

Gcc –O3 _ine.c –o _ine 

然后计算时间

 

 

0 0
原创粉丝点击