2015-11-11 60 views
2

我试图编译这段代码:建筑,当我得到这个错误https://github.com/RanaExMachina/ada-fuse如何在Ada中显式指定泛型类型的大小?

不幸的是:

fuse-system.ads:147:04: size clause not allowed for variable length type 

这似乎是因为它的代码试图设置记录的大小是一个问题,具有通用类型作为条目。这似乎是一个新的错误,因为开发人员在2.5年前撰写这个问题时没有遇到这个问题。不幸的是,他不能在短时间内帮助我,但我必须让图书馆去。然而,在解决这个问题上我有点无奈。

基本上我觉得我不得不告诉gnat这个类型会有多大,与gnat相信的是相反的先验知识:它是一种访问类型。在record或泛型类型定义中。

相关的部分是:

fuse-main.ads: 
    package Fuse.Main is 
    package IO is 
     new Ada.Direct_IO (Element_Type); 
    type File_Access is access IO.File_Type; 

fuse-system.ads: 
    generic 
    type File_Access is private; 
    package Fuse.System is 
    ... 
    type File_Info_Type is record 
     Flags  : Flags_Type; 
     Fh_Old  : Interfaces.C.unsigned_long; 
     Writepage : Interfaces.C.int; 
     Direct_IO : Boolean := True; 
     Keep_Cache : Boolean := True; 
     Flush  : Boolean := True; 
     Nonseekable : Boolean := True; 
     Fh   : File_Access; 
     Lock_Owner : Interfaces.Unsigned_64; 
    end record; 
    type File_Info_Access is access File_Info_Type; 
    pragma Convention (C, File_Info_Type); 
    for File_Info_Type'Size use 32*8; 

我蚊蚋的版本是:4.9.2-1(Debian的杰西)

回答

7

知道File_Access是访问类型,但内Fuse.System编译没有;所有它知道的是它是确定的并且支持分配和平等。实际可能是数百个字节。

告诉编译器,它访问类型,尝试这样的事情(我被压缩成一个包,我的便利,在Mac OS X,因此,64位指针大小;它编译OK):

with Ada.Text_IO; 
package Fuse_Tests is 

    generic 
     type File_Type is limited private; 
     type File_Access is access File_Type; 
    package Fuse_System is 
     type File_Info_Type is record 
     Fh : File_Access; 
     end record; 
     for File_Info_Type'Size use 64; 
    end Fuse_System; 

    type File_Access is access Ada.Text_IO.File_Type; 

    package My_Fuse_System is new Fuse_System 
    (File_Type => Ada.Text_IO.File_Type, 
     File_Access => File_Access); 

end Fuse_Tests; 

或者,替代在评论中建议:

with Ada.Text_IO; 
package Fuse_Tests is 

    generic 
     type File_Type; 
    package Fuse_System is 
     type File_Access is access File_Type; 
     type File_Info_Type is record 
     Fh : File_Access; 
     end record; 
     for File_Info_Type'Size use 64; 
    end Fuse_System; 

    package My_Fuse_System is new Fuse_System 
    (File_Type => Ada.Text_IO.File_Type); 

    -- if needed ... 
    subtype File_Access is My_Fuse_System.File_Access; 

end Fuse_Tests; 
+0

我不知道它是否有意义(或者是有帮助的话),使文件不完整类型在这里。我想我会尝试,并在通用本身中定义访问类型,以便泛型可以在声明实际文件的相同公共部分实例化。 – manuBriot

+0

@manuBriot,我已经包含了你的建议。 –