manual内容如下:
Check order of subprogram bodies. If the letter o appears in the string after -gnaty then all subprogram bodies in a given scope (e.g. a package body) must be in alphabetical order. The ordering rule uses normal Ada rules for comparing strings, ignoring casing of letters, except that if there is a trailing numeric suffix, then the value of this suffix is used in the ordering (e.g. Junk2 comes before Junk10).
我认为 Junk2
的 Junk10
是一种奇怪的风格实现的实际灵感。但是实际触发它的代码示例是什么?我无法使用此选项来提示函数定义或任务主体无序。例如,使用 gnat make -gnatyo
编译以下内容时,我没有收到任何投诉:
procedure Disordered is
function Test return Natural;
function Zest return Natural;
-- disordered function bodies
function Zest return Natural is (1);
function Test return Natural is (2);
begin
null;
end Disordered;
最佳答案
你有:
-- disordered function bodies
function Zest return Natural is (1);
function Test return Natural is (2);
但从技术上讲,这些不是子程序主体。它们被称为表达式函数。这种明确分离的原因是包规范中不允许使用子程序体,而表达式函数则可以。 在示例中使用实际的子程序主体将给出预期的样式警告:
function Zest return Natural is
begin
return 1;
end Zest;
function Test return Natural is
begin
return 2;
end Test;
(既然您提到了任务机构;这些也不是子程序机构)
关于ada - -gnatyo 实际上执行什么样式检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55368994/