运营商类似功能? [英] operators similar to functions?

查看:59
本文介绍了运营商类似功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运算符看起来与函数类似。它们都对

参数或操作数做了些什么,但它们的语法不同。运营商

似乎就像内置的C函数。似乎有非常好的b $ b b有操作数的重要原因,而不仅仅是函数。也许

它们真的很强大,可以在表达式中使用吗?或者他们

以某种方式执行比函数调用更快?我是新手,并且很好奇......感谢所有对这个新闻组的见解..

Operators seem similar to functions. They both do something to either
arguments or operands, but are different in their syntax. Operators
seem to be like built-in C functions. It would seem that there is very
important reasons for having operands, and not just functions. Maybe
they are just really powerful and can be used in expressions? Or they
are somehow executed quicker than a function call? I am a newbie, and
curious.. thanks for all the insights to this newsgroup..

推荐答案

vlsidesign写道:
vlsidesign wrote:

运算符似乎与函数类似。它们都对

参数或操作数做了些什么,但它们的语法不同。运营商

似乎就像内置的C函数。似乎有非常好的b $ b b有操作数的重要原因,而不仅仅是函数。也许

它们真的很强大,可以在表达式中使用吗?或者他们

以某种方式执行比函数调用更快?我是一个新手,并且很好奇......感谢所有对这个新闻组的见解..
Operators seem similar to functions. They both do something to either
arguments or operands, but are different in their syntax. Operators
seem to be like built-in C functions. It would seem that there is very
important reasons for having operands, and not just functions. Maybe
they are just really powerful and can be used in expressions? Or they
are somehow executed quicker than a function call? I am a newbie, and
curious.. thanks for all the insights to this newsgroup..



这是关于方便,以及可读性。并非所有

语言都发现这些非常重要:


(setq x(/( - (sqrt(* 4 ac))b)(* 2 a)))


....是(除非我拙劣的东西)小学的方式

二次方程式出现在一种相当持久的语言中,

不区分功能。来自运营商。


-

Eric Sosman
es ***** @ ieee-dot-org.inva 盖子


vlsidesign< fo **** *@gmail.comwrites:
vlsidesign <fo*****@gmail.comwrites:

运算符似乎与函数类似。它们都对

参数或操作数做了些什么,但它们的语法不同。运营商

似乎就像内置的C函数。似乎有非常好的b $ b b有操作数的重要原因,而不仅仅是函数。也许

它们真的很强大,可以在表达式中使用吗?或者他们

以某种方式执行比函数调用更快?我是一个新手,并且

好​​奇..感谢所有对这个新闻组的见解..
Operators seem similar to functions. They both do something to either
arguments or operands, but are different in their syntax. Operators
seem to be like built-in C functions. It would seem that there is very
important reasons for having operands, and not just functions. Maybe
they are just really powerful and can be used in expressions? Or they
are somehow executed quicker than a function call? I am a newbie, and
curious.. thanks for all the insights to this newsgroup..



你是对的,运营商(大多数)在概念上类似于

函数,在某些语言中(但不是在C语言中),运算符确实被视为函数的
。运算符获取操作数并产生结果;

函数接受参数并返回结果。


一个区别是语法;诸如+之类的运算符和*模仿共同

数学符号。添加*可以*使用

函数语法定义,所以你必须编写``add(x,y)''''而不是

` `x + y'''';后者更方便。你愿意写吗

a + b + c + d



add(a,add(b,add(c,d)) )




另一个区别是操作符内置于语言中,这意味着编译器必须确切地知道他们是如何实施的 - 并且可以利用这些知识。通常

``x + y''''将在生成的代码中通过类似

的ADD指令实现,而不是通过子程序调用实现。 (但是编译器可以为
生成用于显式函数调用的内联代码,并且它可以为不直接实现为

a函数调用>
CPU指令。)此外,允许编译器更自由地重新安排涉及运算符的
重定义表达式而不是函数调用,这对于
往往会产生更多高效生成的代码。


最后,一些运算符可以做一些无法在

函数定义中表达的事情。例如,一个带有两个参数的函数

总是会对它们进行评估;你不能写相当于&&的

或||作为一个函数(至少不在C中)。 +表示+。运营商可以

对任何数字类型进行操作;与功能相同,

你需要为每种类型单独的功能。 "&的sizeof QUOT;实际上是一个

运算符(尽管拼写为关键字而不是

标点符号);没有办法写一个与

相同的功能。


-

Keith Thompson(The_Other_Keith )< ks *** @ mib.org>

在圣地亚哥地区寻找软件开发工作。

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

You''re right, operators (most of them) are conceptually similar to
functions, and in some languages (but not in C), operators really are
treated as functions. An operator takes operands and yields a result;
a function takes arguments and returns a result.

One difference is syntax; operators such as "+" and "*" mimic common
mathematical notation. Addition *could* have been defined using
functional syntax, so you''d have to write ``add(x, y)'''' rather than
``x + y''''; the latter is just more convenient. Would you rather write
a + b + c + d
or
add(a, add(b, add(c, d)))
?

Another difference is that operators are built into the langauge,
which means that the compiler has to know exactly how they''re
implemented -- and can take advantage of that knowledge. Normally
``x + y'''' will be implemented in the generated code by something like
an ADD instruction, not by a subroutine call. (But a compiler can
generate inline code for explicit function calls, and it can generate
a function call for an operator that isn''t directly implemented as a
CPU instruction.) Also, the compiler is allowed a bit more freedom to
rearrange expressions involving operators than function calls, which
tends to make for more efficient generated code.

Finally, some operators can do things that couldn''t be expressed in a
function definition. For example, a function that takes two arguments
always evaluates both of them; you can''t write the equivalent of "&&"
or "||" as a function (at least not in C). The "+" operator can
operate on any numeric type; to do the equivalent with functions,
you''d need a separate function for each type. "sizeof" is actually an
operator (despite being spelled as a keyword rather than as a
punctuation symbol); there''s no way to write a function that does the
same thing.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


vlsidesign写道:
vlsidesign wrote:

运算符似乎与函数类似。它们都对

参数或操作数做了些什么,但它们的语法不同。运营商

似乎就像内置的C函数。似乎有非常好的b $ b b有操作数的重要原因,而不仅仅是函数。也许

它们真的很强大,可以在表达式中使用吗?或者他们

以某种方式执行比函数调用更快?我是一个新手,并且很好奇......感谢所有对这个新闻组的见解..
Operators seem similar to functions. They both do something to either
arguments or operands, but are different in their syntax. Operators
seem to be like built-in C functions. It would seem that there is very
important reasons for having operands, and not just functions. Maybe
they are just really powerful and can be used in expressions? Or they
are somehow executed quicker than a function call? I am a newbie, and
curious.. thanks for all the insights to this newsgroup..



运算符和函数调用之间的区别语法问题完全是一个问题。任何操作符都可以通过

函数实现,并且任何标准库函数都可以定义为

运算符。它并没有真正影响效率 - 一个足够好的b / b
好​​的编译器会生成相同的实际机器代码,无论C是否定义为支持a + b或add(b)b a,b)。


关键的区别在于操作员最多需要输入两到三个
字符才能打字,这样可以更容易打字和更难理解。

另一方面,函数的可读名称通常比运算符长一点,这有助于你记住它们的作用,

更多打字费用。


操作员用于最基本和最常用的操作,所以

,较短的尺寸可以为您节省很多空间和频繁使用

使它们易于记忆。函数用于更复杂的

和更少使用的操作,其中

函数名称的额外大小成本更低,并且不经常使用的优点是

a可读名称更重要。

The distinction between operators and function calls is entirely a
matter of syntax. Any operator could have been implemented by a
function, and any standard library function could have been defined as
an operator. It doesn''t really affect the efficiency - a sufficiently
good compiler would generate the same actual machine code, whether C was
defined as supporting a+b or add(a,b).

The key difference is that operators take at most two or three
characters to type, making them easier to type and harder to understand.
Functions, on the other hand, have readable names which are typically a
bit longer than operators, which helps you remember what they do, at the
expense of more typing.

Operators are used for the most basic and frequently used operations, so
that the shorter size saves you a lot of space, and the frequent use
makes them easy to memorize. Functions are used for the more complicated
and less frequently used operations, where the extra size of the
function name costs less, and the infrequent use makes the advantage of
a readable name more important.


这篇关于运营商类似功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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