簡體   English   中英

為什么這個Ada類型定義導致編譯錯誤?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM