[英]Why is this Ada type definition causing an compilation error?
類型B
的定義等於類型A
的定義,它只是一個較短的形式。 它完美無瑕。
所以我假設類型D
的定義再次等於類型C
的定義。 然而,它會拋出下面打印的編譯器錯誤。 為什么?
type range_T is range 0 .. 255;
type A is array (range_T) of Integer;
type B is array (0 .. 255) of Integer;
type enum_T is (N, S, W, O);
type C is array (enum_T) of Integer;
type D is array (N, S, W, O) of Integer;
$gnatmake hello.adb 2>&1
gcc -c hello.adb
hello.adb:12:27: invalid subtype mark in discrete range
hello.adb:12:30: invalid subtype mark in discrete range
hello.adb:12:33: invalid subtype mark in discrete range
hello.adb:12:36: invalid subtype mark in discrete range
gnatmake: "hello.adb" compilation error
問題是N, S, W, O
不是范圍。 根據語法規則 ,它被視為index_subtype_definitions的序列 - 它顯然不是。
正確的語法(鏡像你問題中的第一組定義)是這樣的:
type enum_T is (N, S, W, O);
type C is array (enum_T) of Integer;
type D is array (N .. O) of Integer;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.