正在加载...
分页: 1/2 第一页 1 2 下页 最后页 [ 显示模式: 摘要 | 列表 ]

gcc 动态编译

[ 2011/10/03 17:24 | by selboo ]
gcc 动态编译(共享库)
  动态编译的可执行文件需要附带一个的动态链接库,在执行时,需要调用其对应动态链接库中的命令。
  
优点:体积小,编译快
缺点:依赖性高
This is The C Code
[root@74-82-173-217 shared]# cat add.c
int add (int x, int y) {
        return x + y;
}
Parsed in 0.004 seconds at 19.18 KB/s
add.c 求和函数
This is The C Code
[root@74-82-173-217 shared]# cat print.c
#include <stdio.h>
void print (int x) {
       printf ("%d\n",x);
}
Parsed in 0.004 seconds at 26.43 KB/s
print 打印函数
Tags: , ,

gcc 静态编译

[ 2011/10/01 19:32 | by selboo ]
gcc 静态编译
        就是在编译的时候把你所有的模块和库文件编译到一个可执行文件中,当你启动这个程序的时候所有模块和库加载到内存。加快程序执行效率,
优点:速度快,依赖性低
缺点:体积大,加载慢
This is The C Code
[root@74-82-173-217 static]# cat add.c
int add (int x, int y) {
        return x + y;
}
Parsed in 0.005 seconds at 17.41 KB/s
add.c 求和函数
This is The C Code
[root@74-82-173-217 static]# cat print.c
#include <stdio.h>
void print (int x) {
       printf ("%d\n",x);
}
Parsed in 0.005 seconds at 22.63 KB/s
print 打印函数
Tags: , ,

C 可变长参数

[ 2011/09/02 21:03 | by selboo ]
      其实我们接触的第一个C语言函数 int printf(const char *format, ...);就是可变长参数实现的。open函数就有两个原型 int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode);
但是这并不是函数重载,因为C语言是不支持函数重载的。这是利用变长参数实现的。
This is The C Code
[root@selboo.com.cn ~]$ cat c.c
#include <stdio.h>
int main ()
{
        int a = 1, b = 2;
        printf ("Selboo...\n");
}
[root@selboo.com.cn ~]$ gcc c.c
[root@selboo.com.cn ~]$ ./a.out
Selboo...
Parsed in 0.005 seconds at 41.89 KB/s

上面 printf 就是可变长参数,它的原型声明 在 stdio.h 里面可以找到.
Tags: , ,

C return ;

[ 2011/08/13 13:59 | by selboo ]
      C语言的程序员都知道,每次代码结束以后都要加一个return 0,这个return 0表示程序运行成功,非“0” 表示错误或异常,这个和机器和操作系统有关一般是   0 为正常退出  非0 为非正常退出

      return函数的作用大多数判断一个函数是否成功完成,main 函数的返回值用于说明程序的退出状态.如果返回 0,则代表程序正常退出,否则代表程序异常退出.下面我们在 Linux 环境下做个小测试。




[root@74-82-173-217 c]# cat r.c
#include <stdio.h>

int main () {
        printf ("main 1\n");
        return 0;
        printf ("main 2\n");
}
[root@74-82-173-217 c]# gcc r.c
[root@74-82-173-217 c]# ./a.out
main 1
[root@74-82-173-217 c]# echo $?
0
Tags:

Windows上创建硬链接

[ 2010/09/27 16:33 | by selboo ]
  Unix上可以方便的创建软链接和硬链接。可以提供额外的访问文件的接口而无需复制文件,大大减小了重复文件的空间浪费和维护问题,也减少了大文件复制的开销。
  Windows上只能创建硬链接(快捷方式有点类似软链接,不过还是有不小的区别的),要求Win2000以上,而且只能在NTFS分区上用,也不能跨分区创建链接。但起码比没有好。
  下面这个程序就是用来创建硬链接的。建立以后,修改一下其中一个文件,看一下另一个是不是也一起变了。^_^

  用法:编译以后,比如生成nthl.exe。
     nthl 目标链接 原始文件
  如果发生错误,会输出错误信息。

源代码:

[code]/* nthl.cpp */
/**
* 创建硬链接
*
* @author XieZhenye
*
*/
#ifdef _WIN32_WINNT
    #undef _WIN32_WINNT<br/&#
Tags: , , , ,
分页: 1/2 第一页 1 2 下页 最后页 [ 显示模式: 摘要 | 列表 ]