内置sqrt()? [英] Build-in sqrt()?

查看:101
本文介绍了内置sqrt()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



大家好,

为什么这个c代码可以在没有-lm的情况下编译和链接?


#include< math.h>

#include< stdio.h>

int main()

{

printf("%f\ n",sqrt(2.0));

返回0;

}


当我使用nm列出目标文件中的符号时,甚至没有sqrt符号


有人可以给我一个提示吗?我正在使用gcc-4.1.2和glibc2.4.1

linux


最好的问候


hello everyone,

why this c code can be compiled and linked without -lm?

#include<math.h>
#include<stdio.h>
int main()
{
printf("%f\n",sqrt(2.0));
return 0;
}

even NO sqrt symbol when i use nm to list symbols from the object file

someone can give me a hint? i''m using a gcc-4.1.2 with glibc2.4.1 under
linux

best regards

推荐答案

pe ********* @ gmail。 com 写道:

大家好,

为什么这个c代码可以编译和链接而不用-lm ?


#include< math.h>

#include< stdio.h>

int main()

{

printf("%f \ nn",sqrt(2.0));

返回0;

当我使用nm列出目标文件中的符号时,
甚至没有sqrt符号


有人可以给我一个提示吗?我正在使用gcc-4.1.2和glibc2.4.1

linux
hello everyone,

why this c code can be compiled and linked without -lm?

#include<math.h>
#include<stdio.h>
int main()
{
printf("%f\n",sqrt(2.0));
return 0;
}

even NO sqrt symbol when i use nm to list symbols from the object file

someone can give me a hint? i''m using a gcc-4.1.2 with glibc2.4.1 under
linux



从C创建可执行代码的实际细节源是

实现依赖,C标准没有说明它。

在UNIX下,传统上数学库是一个

单独的文件,因此必须在链接时具体包括。一个

特定的实现可能包括数学函数以及

标准C库的其余部分。


标准C,对于你的

观察真的没什么可说的。

The actual details of creating executable code from C source is
implementation dependant and the C standard says nothing about it.
Under UNIX it is traditionally the case that the math library is a
seperate file and hence has to be specifically included at link time. A
specific implementation may well include the math functions along with
the rest of the standard C library.

Standard C, and this group, really has nothing to say about your
observation.


pe ********* @ gmail.com 写道:
pe*********@gmail.com wrote:

why这个c代码可以在没有-lm的情况下编译和链接吗?

#include< math.h>

#include< stdio.h>

int main()

{

printf("%f\ nn",sqrt(2.0));

返回0;

}

当我使用nm列出目标文件中的符号时,
甚至没有sqrt符号


有人可以给我一个提示吗?我正在使用gcc-4.1.2和glibc2.4.1

linux
why this c code can be compiled and linked without -lm?

#include<math.h>
#include<stdio.h>
int main()
{
printf("%f\n",sqrt(2.0));
return 0;
}

even NO sqrt symbol when i use nm to list symbols from the object file

someone can give me a hint? i''m using a gcc-4.1.2 with glibc2.4.1 under
linux



首先阅读你方便的文档,例如

%info gcc

然后询问具体的进一步问题
gc ******@gcc.gnu.org

如果您有兴趣,请检查生成的代码,看看是否评估了sqrt()

编译时,或在运行时使用内置CPU

指令。

First read your handy docs, e.g.
% info gcc
then ask specific further questions on
gc******@gcc.gnu.org
If you are interested, check your generated code to see whether sqrt()
was evaluated at compile time, or at run time using a built-in CPU
instruction.


2006年11月26日20:05:09 -0800, pe ********* @ gmail.com

< pe ********* @ gmail.comwrote in comp.lang.c:
On 26 Nov 2006 20:05:09 -0800, "pe*********@gmail.com"
<pe*********@gmail.comwrote in comp.lang.c:

>

大家好,

为什么这个c代码可以编译和链接而不用 - LM?
>
hello everyone,

why this c code can be compiled and linked without -lm?



什么是-lm?它没有被C语言定义。如果它是你认为你的实现需要的东西,那么你应该在支持小组中询问你的实现。

What''s "-lm"? It''s nothing defined by the C language. If it''s
something that you think your implementation needs, you should be
asking in a support group for your implementation.


#include< math.h>

#include< stdio.h>

int main()

{

printf("%f\ nn",sqrt(2.0));

返回0;

}
<当我用nm来列出目标文件中的符号时,
甚至没有sqrt符号
#include<math.h>
#include<stdio.h>
int main()
{
printf("%f\n",sqrt(2.0));
return 0;
}

even NO sqrt symbol when i use nm to list symbols from the object file



C标准没有提到nm,或者它应该做什么。

同样,一个特定于平台的小组是合适的,可能

提供更多有用的信息。

The C standard names no mention of "nm", or what it is supposed to do.
Again, a platform specific group is appropriate and could probably
provide more useful information.


有人可以给我一个提示吗?我正在使用gcc-4.1.2和glibc2.4.1

linux


最好的问候
someone can give me a hint? i''m using a gcc-4.1.2 with glibc2.4.1 under
linux

best regards



在其他可能性中,as-if规则允许实现

用已知结果替换具有常量值

的标准库函数的调用。它可能只是通过

1.4142135623730950488016887242097,或者可能是一些较短的版本

,而不是直接调用sqrt()来获取printf()。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://c-faq.com/

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

Among other possibilities, the as-if rule allows the implementation to
replace the call of a standard library function with a constant value
with its known result. It could merely pass
1.4142135623730950488016887242097, or perhaps some shorter version
thereof, to printf() without calling sqrt() at all.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


这篇关于内置sqrt()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆