On 10 May 2003 at 3:30, Frank Heckenbach wrote:
Prof A Olowofoyeku (The African Chief) wrote:
This program does not compile. Shouldn't it?
Program attribute_bug;
TYPE Int8 = Integer attribute ( Size = 8 );
WordRec : RECORD Lo, Hi : Cardinal attribute ( Size = 8 ); END;
LongRec = PACKED RECORD Lo, Hi : Cardinal attribute ( Size = 16 ); END;
Begin Writeln ('OK'); End.
Attributes currently don't work in record fields etc. It would be extra effort to recognize them (syntactically). But since one can always declare a type with attributes (such as `Int8') and use this in the record, I'm not conviced whether I should do it ...
Ok. Look at this record (in existing WinAPI import units): TYPE tBits = PACKED RECORD BaseMid : Cardinal ( 8 ); Typ : Cardinal ( 5 ); Dpl : Cardinal ( 2 ); Pres : Cardinal ( 1 ); LimitHi : Cardinal ( 4 ); Sys : Cardinal ( 1 ); Reserved_0 : Cardinal ( 1 ); Default_Big : Cardinal ( 1 ); Granularity : Cardinal ( 1 ); BaseHi : Cardinal ( 8 ) END;
I have to change my code to define at least 4 different types for this. Consider many more structures of this kind. Of course the work can be done, even if tedious - but one would then have a proliferation of types just to be able to create one record. I will do the work, but you might want to reconsider this matter.
One reason against it is that it's not possible in arrays, sets and files because then the following would be ambiguous (does the attribute belong to the array of the component type?). So it might be more consistent to not allow it in any structured types.
Perhaps.
I have another problem. This code used to compile:
unit attrbug_2; interface uses GPC; FUNCTION DirectoryExists ( CONST DirName : String ) : Boolean; attribute (name = '_p_DirectoryExists'); external; FUNCTION FileSearch ( CONST FileName, DirList : String ) : TString; attribute (name = '_p_FSearch'); external; implementation end.
Now, it dies with this error: "attributes in forward declared routines are not allowed". If "external" is removed, then you get an error like "unresolved forward declaration `FileSearch'".
This code is taken from the Sysutils unit, which exports some functions that already exist in the GPC unit. In older times, you just asmnamed them. In the penultimate snapshot, that was changed to the above. Now, it doesn't work. I need this to work (or at least I need to have a way to reexport routines from other units). This is reminiscent of the earlier discussions on unit propagation. I am not sure how that discussion was resolved.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~african_chief/