g++比gcc对c的支持更好???

软件和网站开发以及相关技术探讨
回复
头像
cuihao
帖子: 4793
注册时间: 2008-07-24 11:33
来自: 郑州
联系:

g++比gcc对c的支持更好???

#1

帖子 cuihao » 2008-11-29 8:49

真奇怪,我编得复杂的c程序,用gcc编译一大堆警告,g++却没事,而且貌似c99标准也支持的很好,怎么回事呀~~~
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 绿
Site: CUIHAO.TK    Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

Re: g++比gcc对c的支持更好???

#2

帖子 BigSnake.NET » 2008-11-29 12:20

贴源码。。。
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
cuihao
帖子: 4793
注册时间: 2008-07-24 11:33
来自: 郑州
联系:

Re: g++比gcc对c的支持更好???

#3

帖子 cuihao » 2008-11-29 14:04

程序太长了,随便贴一个子函数:

代码: 全选

#include<stdio.h>
#include<math.h>
#include<string.h>

double fc(char *s,double a,double b)
{
 double rtn;

 if (strcmp(s,"abs")==0) rtn=fabs(a);
 if (strcmp(s,"ln")==0) rtn=log(a);
 if (strcmp(s,"exp")==0) rtn=exp(a);
 if (strcmp(s,"sqr")==0) rtn=a*a;
 if (strcmp(s,"sqrt")==0) rtn=sqrt(a);
 if (strcmp(s,"int")==0) rtn=trunc(a);
 if (strcmp(s,"rnd")==0) rtn=round(a);
 if (strcmp(s,"hypot")==0) rtn=hypot(a,b);

 return rtn;
}

int main(void)
{
 return 0;
}
g++编译可以,gcc出一些莫名其妙的东东:

代码: 全选

/home/cuihao/Desktop/tt.c: 在函数‘fc’中:
/home/cuihao/Desktop/tt.c:15: 警告: 隐式声明与内建函数‘trunc’不兼容
/home/cuihao/Desktop/tt.c:16: 警告: 隐式声明与内建函数‘round’不兼容
/tmp/cch40gfh.o: In function `fc':
tt.c:(.text+0x5b): undefined reference to `log'
tt.c:(.text+0x80): undefined reference to `exp'
tt.c:(.text+0xd9): undefined reference to `sqrt'
tt.c:(.text+0x104): undefined reference to `trunc'
tt.c:(.text+0x129): undefined reference to `round'
tt.c:(.text+0x155): undefined reference to `hypot'
collect2: ld 返回 1
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 绿
Site: CUIHAO.TK    Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

Re: g++比gcc对c的支持更好???

#4

帖子 BigSnake.NET » 2008-11-29 14:10

gcc a.c -std=c99 -lm
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
cuihao
帖子: 4793
注册时间: 2008-07-24 11:33
来自: 郑州
联系:

Re: g++比gcc对c的支持更好???

#5

帖子 cuihao » 2008-11-29 14:28

喔~~~可以了~谢谢
那个-lm是什么意思
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 绿
Site: CUIHAO.TK    Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
头像
HuntXu
帖子: 5776
注册时间: 2007-09-29 3:09

Re: g++比gcc对c的支持更好???

#6

帖子 HuntXu » 2008-11-29 14:48

math库
HUNT Unfortunately No Talent...
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

Re: g++比gcc对c的支持更好???

#7

帖子 xhy » 2008-11-29 15:12

g++只是个马甲,它用一堆参数调用了gcc

g++不是编译器,只是个外壳
目前负债150多万
头像
ChloeRei
帖子: 1021
注册时间: 2007-11-23 9:49

Re: g++比gcc对c的支持更好???

#8

帖子 ChloeRei » 2008-11-30 11:46

xhy 写了:g++只是个马甲,它用一堆参数调用了gcc

g++不是编译器,只是个外壳
:ema6 不是反过来么
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

Re: g++比gcc对c的支持更好???

#9

帖子 xhy » 2008-11-30 12:19

ChloeRei 写了:
xhy 写了:g++只是个马甲,它用一堆参数调用了gcc

g++不是编译器,只是个外壳
:ema6 不是反过来么

代码: 全选

man gcc
有这么一条

代码: 全选

       However, the use of gcc does not add the C++ library.  g++ is a program that calls GCC and treats .c, .h and .i files as
       C++ source files instead of C source files unless -x is used, and automatically specifies linking against the C++
       library.  This program is also useful when precompiling a C header file with a .h extension for use in C++ compilations.
       On many systems, g++ is also installed with the name c++.
目前负债150多万
头像
ChloeRei
帖子: 1021
注册时间: 2007-11-23 9:49

Re: g++比gcc对c的支持更好???

#10

帖子 ChloeRei » 2008-11-30 19:57

奥,原来我想错了
回复