Gne*_*nte 1 private constants ada renaming
我想在私有部分中定义的包的公共部分(原始名称已弃用)中重命名常量.我试过这个,但GNAT说:
完全不变的声明似乎为时已晚
package Sample is
type The_Type is private;
My_Constant : constant The_Type;
My_Renamed_Constant : The_Type;
private
type The_Type is ...;
My_Constant : constant The_Type := ...;
My_Renamed_Constant : The_Type renames My_Constant;
end Sample;
Run Code Online (Sandbox Code Playgroud)
您是否有理由想要重命名而不是(比如)
function My_Renamed_Constant return The_Type;
只是在包体中返回My_Constant?
功能相同......如果您担心速度,应该内联.
稍后在弃用过程中,改为My_Renamed_Constant使用常量和My_Constant函数.然后,当您认为自己已准备好退休时,请function My_Constant提高Program_Error或自定义异常,指示"使用已弃用的常量"来捕获您错过的任何用法.