什么是&QUOT的定义;运算"在C99? [英] What is the definition of "arithmetic operation" in C99?

查看:143
本文介绍了什么是&QUOT的定义;运算"在C99?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C99,术语的算术运算的出现16次,但我没有看到一个定义它。

术语的算术运算符的只有两次在文本(同样没有定义)出现,但它会出现在索引:


  

算术运算符


  
  

    

添加剂,6.5.6,G.5.2

    按位,6.5.10,6.5.11,6.5.12

    增量和减量,6.5.2.4,6.5.3.1

    乘6.5.5,G.5.1

    转变,6.5.7

    一元,6.5.3.3


  

然后我们有 + - | &安培; (二进制) ++ - * (二进制) / <&LT ; >> 算术运算符,如果该指数被认为是规范!

也许我们应该明确的算术运算的作为是用算术运算符的。但是F9.4.5说,的sqrt()函数也是算术运算,并指IEC 60559(亦称IEEE754)了解详情。所以,必须有这不只​​是使用算术运算的算术运算。


解决方案

由于我们没有一个正式的定义,让我们看看我们是否能够拼凑多么的算术运算的理由间pretation 应该的。这将是投机性的,但我无法找到管这个任何明显的缺陷报告或公开的问题。

我想我会用什么被认为是算术类型,它是覆盖在部分启动 6.2.5 类型的段落的 18 的说(的重点煤矿前进的):


  

整数和浮点类型统称为算术类型。
  每个算术类型属于一种类型的域:真正的类型域
  包括实数类型,复杂类型域包括
  复杂的类型。


好了,我们知道,一个运算必须在一个整数或浮点数类型进行操作。那么,什么是一个的操作的?好像我们的定义,从部分 5.1.2.3 程序执行的段落的 2 的它说有一个好走:


  

访问的易失性对象,修改一个对象,修改文件,或
  打电话,做任何的这些操作的函数都是一面
  效果, 11)这是在执行状态的变化
  环境。 [...]


所以修改对象或调用这样做,这是一个操作的功能。什么是的对象的?第 3.14 说:


  

在执行环境中的数据存储的区域,该内容
  它可以重新present值


虽然标准似乎使用的短线操作较为松散意味着评估,例如在部分 7.12.1 的错误情况治疗的它说:


  

在为所有指定的每个的功能的行为
  再它的输入参数presentable值,除非声明
  除此以外。 每个功能应当执行,就好像它是一个单一的
  操作
,而不会产生任何外部可见例外
  条件。


和第 6.5 防爆pressions 的段落的 8 的它说:


  

一个浮动的前pression可能会收缩,也就是评为虽然
  它是一个原子操作[...]


因此​​,这似乎意味着,一个评估是一个操作

因此​​,将这些部分是pretty似乎太多所有的算术运算符和任何数学函数应该属于常识定义下的算术运算

In C99, the term arithmetic operation appears 16 times, but I don't see a definition for it.

The term arithmetic operator only appears twice in the text (again without definition) but it does appear in the Index:

arithmetic operators

additive, 6.5.6, G.5.2
bitwise, 6.5.10, 6.5.11, 6.5.12
increment and decrement, 6.5.2.4, 6.5.3.1
multiplicative 6.5.5, G.5.1
shift, 6.5.7
unary, 6.5.3.3

Then we have + - | &(binary) ++ -- *(binary) / % << >> ~ as arithmetic operators, if the Index is considered normative!

Perhaps we should identify arithmetic operation as being the use of an arithmetic operator. But F9.4.5 says that the sqrt() function is also an arithmetic operation, and refers to IEC 60559 (aka. IEEE754) for details. So there must be arithmetic operations that are not just the use of arithmetic operators.

解决方案

Since we don't have a formal definition let's see if we can piece together a rationale interpretation of what an arithmetic operation should be. This will be speculative but I can not find any obvious defect reports or open issues that cover this.

I guess I would start with what are considered arithmetic types, which is covered in section 6.2.5 Types paragraph 18 says (emphasis mine going forward):

Integer and floating types are collectively called arithmetic types. Each arithmetic type belongs to one type domain: the real type domain comprises the real types, the complex type domain comprises the complex types.

ok, so we know that an arithmetic operation has to operate on either an integer or a floating point type. So what is an operation? It seems like we have a good go at defining that from section 5.1.2.3 Program execution paragraph 2 which says:

Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects,11) which are changes in the state of the execution environment. [...]

So modifying an object or call a function that does that, it is an operation. What is an object? Section 3.14 says:

region of data storage in the execution environment, the contents of which can represent values

Although the standard seems to use the term operation more loosely to mean an evaluation, for example in section 7.12.1 Treatment of error conditions it says:

The behavior of each of the functions in is specified for all representable values of its input arguments, except where stated otherwise. Each function shall execute as if it were a single operation without generating any externally visible exceptional conditions.

and in section 6.5 Expressions paragraph 8 which says:

A floating expression may be contracted, that is, evaluated as though it were an atomic operation [...]

So this would seem to imply that an evaluation is an operation.

So it would seem from these sections that pretty much all the arithmetic operators and any math function would fall under a common sense definition of arithmetic operation.

这篇关于什么是&QUOT的定义;运算&QUOT;在C99?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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