残念ながら、C const
では、変数は実際にはconstではありません。
下記はc99標準からの抽出物である。
6.6 Constant expressions
(7) More latitude is permitted for constant expressions in initializers. Such a constant expression shall be, or evaluate to, one of the following:
— an arithmetic constant expression,
— a null pointer constant,
— an address constant, or
— an address constant for an object type plus or minus an integer constant expression.
(8) An arithmetic constant expression shall have arithmetic type and shall only have operands that are integer constants, floating constants, enumeration constants, character constants, and sizeof expressions. Cast operators in an arithmetic constant expression shall only convert arithmetic types to arithmetic types, except as part of an operand to a sizeof operator whose result is an integer constant.
したがって、c
とa
は定数式ではなく、として使用することができない次のよう
6.4.4 Constants
Syntax
constant:
integer-constant (e.g. 4, 42L)
floating-constant (e.g. 0.345, .7)
enumeration-constant (stuff in enums)
character-constant (e.g. 'c', '\0')
標準は定数式を定義して次のよう
6.7.8 Initialization
- All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals.
定数が定義されていますあなたのケースのイニシャライザ。
外観は、この前に何度も頼まれました。尋ねる前にこのサイトを検索してください。 –
私はあなたのコードをちゃんとコンパイルすることができます。どのコンパイラ/システムを使用していますか? – none
@ gokcehan:万が一C++コンパイラを使用していますか? –