为什么 GNAT 中预定义的单元文件名只有 8 个字符?

Why are predefined unit file names in GNAT only 8 characters?

我正在为 Arduino Due 构建运行时,基于 this work by Brent Seidel. The board uses an Atmel SAM3X8E processor, which as you might notice is a seven-letter name. Brent makes this note in the file a-sam3x8.ads:

--  This package should be called "System.Sam3x8e", but after lots of testing,
--  it seems that for some reason it just wouldn't find the package.  Calling
--  the package "System.Sam3x8" does work.

确实,经过我自己的测试,我无法使用 "proper" 名称构建运行时。仔细检查后,我注意到 GNAT 和其他 BSP 中的所有预定义文件似乎都只有六个字母长,加上 GNAT documentation on file naming rules 中描述的前缀。还有一些关于 gnatkr 和 "krunching" 文件名的信息是一定数量的字符,甚至还有一个预定义单元被压缩到 8 个字符的示例。但是,我找不到关于为什么 预定义单位被缩短的任何解释。

我想解决这个特殊情况,我可以将包命名为 System.SAM3X8E 然后 krunch 或添加 pragma Source_File_Name,但我真的宁愿只使用描述性文件名。事实上,如果我可以重命名 所有 预定义文件以使用它们的全名,我会很高兴。我知道他们会很长,但我宁愿有一个长的、描述性的名字,也不愿有六个字母的字母数字混乱。

如前所述, this limitation is an accommodation for 8.3 filenames, comprised of no more than eight characters and an optional extension. As noted by @Zerte, GNAT came out ca. 1995 with the advent of Ada 95, a time when DOS was still popular and Windows ran atop DOS. Moreover, all file systems have name length limits,而描述性包名称和层次结构深度则没有。实现在如何适应后者方面有所不同,但 GNAT 使用文件系统。

请注意,gnatkr 只是将包名称转换为满足您问题中引用的 file naming rules 的文件名。

$ gnatkr System.Sam3x8e.adb
s-sam3x8.adb

应该可以在名为 s-sam3x8.ads

的文件中包含一个名为 System.Sam3x8e 的包
package System.Sam3x8e is…

这将允许其他编译单元在上下文子句中引用全名:

with System.Sam3x8e;