是什么导致了这个 Ada 编译错误 "ambiguous character literal"?
What caused this Ada compilation error "ambiguous character literal"?
我有这个 Ada 代码。
with Ada.Text_IO;
use Ada.Text_IO;
procedure for_Loop is
begin
for Counter in 'A'..'Z' loop
Put(Counter);
end loop;
New_Line;
end for_Loop;
Ada 编译器 (gnatmake) 输出这些错误消息。
gcc -c for_loop.adb
for_loop.adb:6:24: ambiguous character literal
for_loop.adb:6:24: possible interpretation: Character
for_loop.adb:6:24: possible interpretation: Wide_Character
for_loop.adb:6:24: possible interpretation: Wide_Wide_Character
gnatmake: "for_loop.adb" compilation error
代码有什么问题?
来自this post:
The problem is that 'A' and 'Z' could be from either Character or Wide_Character. The simplest correction is to make the type explicit; e.g.: for Char in Character range 'A' .. 'Z' loop ... end loop;
with Ada.Text_IO;
use Ada.Text_IO;
procedure for_Loop is
begin
for Counter in Character range 'A'..'Z' loop
Put(Counter);
end loop;
New_Line;
end for_Loop;
这是输出:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
我有这个 Ada 代码。
with Ada.Text_IO;
use Ada.Text_IO;
procedure for_Loop is
begin
for Counter in 'A'..'Z' loop
Put(Counter);
end loop;
New_Line;
end for_Loop;
Ada 编译器 (gnatmake) 输出这些错误消息。
gcc -c for_loop.adb
for_loop.adb:6:24: ambiguous character literal
for_loop.adb:6:24: possible interpretation: Character
for_loop.adb:6:24: possible interpretation: Wide_Character
for_loop.adb:6:24: possible interpretation: Wide_Wide_Character
gnatmake: "for_loop.adb" compilation error
代码有什么问题?
来自this post:
The problem is that 'A' and 'Z' could be from either Character or Wide_Character. The simplest correction is to make the type explicit; e.g.: for Char in Character range 'A' .. 'Z' loop ... end loop;
with Ada.Text_IO;
use Ada.Text_IO;
procedure for_Loop is
begin
for Counter in Character range 'A'..'Z' loop
Put(Counter);
end loop;
New_Line;
end for_Loop;
这是输出:
ABCDEFGHIJKLMNOPQRSTUVWXYZ