_Complex常量 [英] _Complex constant

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

问题描述

有没有办法创建一个double _Complex类型的常量而没有

包括< complex.h>?


为什么_Complex_I是一个宏不是实现定义的常量?


谢谢。


a +,ld。

解决方案

Laurent Deniau写道:


有没有办法在没有

的情况下创建double _Complex类型的常量< complex.h> ;?


>来自C99理由:



"我指定的后缀虚数常量不是必需的,因为

乘以I提供了一个足够方便且更多的

通常用于虚数术语的符号。


因此,除非你计算特定于实现的扩展,或者虚数部分为0的复杂的
常量,否则可能不是。


为什么_Complex_I是宏而不是实现定义的常量?



常量不能用于常量表达式。


#include< complex.h>

const double complex i = I; / *或等价,_Complex_I * /

复数复数v = 1 + 2 * i; / *错误:初始化元素不是

常数* /


Harald van D?3k写道:
< blockquote class =post_quotes>
Laurent Deniau写道:


>>有没有办法在没有包括< complex.h>?



>>来自C99理由:



" ;不需要用于指定虚构常量的I后缀,因为

乘以I提供了一个足够方便且更多的b $ b通常用于虚构术语的符号。


因此,除非你计算特定于实现的扩展,或复数

常数,假想部分为零,否则可能不是。


>>为什么_Complex_I是宏而不是实现定义的常量?




常量不能用于常量表达式。


#include< complex.h> ;

const double complex i = I; / *或等价,_Complex_I * /

复数复数v = 1 + 2 * i; / *错误:初始化元素不是

常数* /



对。通过指定''实现定义的常量'',我想是一个特殊的常量,如空指针常量。像__builtin_Complex_I那样将某些东西扩展到编译器常量。


我的问题是即使包含complex.h,gcc(4.1.2)在c99迂腐模式下给出一个

警告代码:


const double complex i = _Complex_I;


警告:虚构常量是GCC扩展


在complex.h中我们发现(如你所说):


#define _Complex_I(__extension__ 1.0iF)


看来这个警告不合适,但gcc无法用这个定义知道

。任何线索?


谢谢。


a +,ld。


< blockquote> Laurent Deniau写道:


Harald van D?3k写道:


Laurent Deniau写道:


>为什么_Complex_I是宏而不是实现定义的常量?



常量不能用于常量表达式。



对。通过指定''实现定义的常量'',我想是一个特殊的常量,如空指针常量。例如,将
扩展为编译器常量的东西,例如__builtin_Complex_I。



嗯,这基本上是_Complex_I必须要做的。 (不是

标准明确,但我无法想象实现

会如何支持它。)如下所示,GCC使用编译器

常数本身。


我的问题是即使包含complex.h,gcc(4.1.2)给出了
$ b c99迂腐模式中的$ b警告代码:


const double complex i = _Complex_I;


警告:虚构常量是GCC扩展名


in complex.h我们发现(如你所说):


#define _Complex_I(__extension__ 1.0iF)


看来这个警告不合适,但gcc无法用这个定义知道

。任何线索?



这是海湾合作委员会长期存在的错误:
http://gcc.gnu.org/PR7263


除了忽略警告之外别无他法,或使用

不同的编译器。


Is there any way to create a constant of type double _Complex without
including <complex.h>?

Why _Complex_I is a macro an not an implementation-defined constant?

Thanks.

a+, ld.

解决方案

Laurent Deniau wrote:

Is there any way to create a constant of type double _Complex without
including <complex.h>?

>From the C99 rationale:

"An I suffix to designate imaginary constants is not required, as
multiplication by I provides a sufficiently convenient and more
generally useful notation for imaginary terms."

So unless you count implementation-specific extensions, or complex
constants with an imaginary part of zero, then no, probably not.

Why _Complex_I is a macro an not an implementation-defined constant?

Constants can''t be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */


Harald van D?3k wrote:

Laurent Deniau wrote:

>>Is there any way to create a constant of type double _Complex without
including <complex.h>?


>>From the C99 rationale:

"An I suffix to designate imaginary constants is not required, as
multiplication by I provides a sufficiently convenient and more
generally useful notation for imaginary terms."

So unless you count implementation-specific extensions, or complex
constants with an imaginary part of zero, then no, probably not.

>>Why _Complex_I is a macro an not an implementation-defined constant?



Constants can''t be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */

Right. By specifying ''implementation-defined constant'' I was thinking to
a special constant like null pointer constant. Something that would
expand to a compiler constant like __builtin_Complex_I for example.

My problem is that even with complex.h included, gcc (4.1.2) gives a
warning in c99 pedantic mode for the code:

const double complex i = _Complex_I;

warning: imaginary constants are a GCC extension

in complex.h we find (as you mention it):

#define _Complex_I (__extension__ 1.0iF)

It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?

Thanks.

a+, ld.


Laurent Deniau wrote:

Harald van D?3k wrote:

Laurent Deniau wrote:

>Why _Complex_I is a macro an not an implementation-defined constant?

Constants can''t be used in constant expressions.


Right. By specifying ''implementation-defined constant'' I was thinking to
a special constant like null pointer constant. Something that would
expand to a compiler constant like __builtin_Complex_I for example.

Well, that''s basically what _Complex_I is required to do already. (Not
explicitly by the standard, but I can''t imagine how an implementation
would support it otherwise.) As you show below, GCC uses a compiler
constant itself.

My problem is that even with complex.h included, gcc (4.1.2) gives a
warning in c99 pedantic mode for the code:

const double complex i = _Complex_I;

warning: imaginary constants are a GCC extension

in complex.h we find (as you mention it):

#define _Complex_I (__extension__ 1.0iF)

It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?

That''s a long-standing bug in GCC:
http://gcc.gnu.org/PR7263

There''s not much else to do but either ignore the warning, or use a
different compiler.


这篇关于_Complex常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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