本文介绍了_Complex常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有没有办法创建一个double _Complex类型的常量而没有 包括< complex.h>? 为什么_Complex_I是一个宏不是实现定义的常量? 谢谢。 a +,ld。 解决方案 "我指定的后缀虚数常量不是必需的,因为 乘以I提供了一个足够方便且更多的 通常用于虚数术语的符号。 因此,除非你计算特定于实现的扩展,或者虚数部分为0的复杂的常量,否则可能不是。 常量不能用于常量表达式。 #include< complex.h> const double complex i = I; / *或等价,_Complex_I * / 复数复数v = 1 + 2 * i; / *错误:初始化元素不是 常数* / " ;不需要用于指定虚构常量的I后缀,因为 乘以I提供了一个足够方便且更多的b $ b通常用于虚构术语的符号。 因此,除非你计算特定于实现的扩展,或复数 常数,假想部分为零,否则可能不是。 常量不能用于常量表达式。 #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。 Laurent Deniau写道: 常量不能用于常量表达式。 对。通过指定''实现定义的常量'',我想是一个特殊的常量,如空指针常量。例如,将扩展为编译器常量的东西,例如__builtin_Complex_I。 嗯,这基本上是_Complex_I必须要做的。 (不是 标准明确,但我无法想象实现 会如何支持它。)如下所示,GCC使用编译器 常数本身。 这是海湾合作委员会长期存在的错误: http://gcc.gnu.org/PR7263 除了忽略警告之外别无他法,或使用 不同的编译器。 Is there any way to create a constant of type double _Complex withoutincluding <complex.h>? Why _Complex_I is a macro an not an implementation-defined constant? Thanks. a+, ld. 解决方案 "An I suffix to designate imaginary constants is not required, asmultiplication by I provides a sufficiently convenient and moregenerally useful notation for imaginary terms." So unless you count implementation-specific extensions, or complexconstants with an imaginary part of zero, then no, probably not. 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 notconstant */ "An I suffix to designate imaginary constants is not required, asmultiplication by I provides a sufficiently convenient and moregenerally useful notation for imaginary terms."So unless you count implementation-specific extensions, or complexconstants with an imaginary part of zero, then no, probably not. 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 notconstant */Right. By specifying ''implementation-defined constant'' I was thinking toa special constant like null pointer constant. Something that wouldexpand to a compiler constant like __builtin_Complex_I for example. My problem is that even with complex.h included, gcc (4.1.2) gives awarning 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 withthis definition. Any clue? Thanks. a+, ld. Constants can''t be used in constant expressions. Right. By specifying ''implementation-defined constant'' I was thinking toa special constant like null pointer constant. Something that wouldexpand to a compiler constant like __builtin_Complex_I for example.Well, that''s basically what _Complex_I is required to do already. (Notexplicitly by the standard, but I can''t imagine how an implementationwould support it otherwise.) As you show below, GCC uses a compilerconstant itself. 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 adifferent compiler. 这篇关于_Complex常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 08:29