What caused this Ada compilation error “ambiguous character literal”?

南笙酒味 提交于 2019-12-13 05:02:23

问题


I have this Ada code.

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;

The Ada compiler (gnatmake) outputs these error message.

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

What's wrong with the code?


回答1:


From 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;

This is the oupput:

ABCDEFGHIJKLMNOPQRSTUVWXYZ


来源:https://stackoverflow.com/questions/29934365/what-caused-this-ada-compilation-error-ambiguous-character-literal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!