gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] Arithmetic operations on values of type FilePos (ISO I/O Library)


From: Benjamin Kowarsch
Subject: [Gm2] Arithmetic operations on values of type FilePos (ISO I/O Library)
Date: Sat, 29 Jul 2017 21:13:55 +0900

Hi Modulans

I have a portability layer for I/O. It is meant to be portable across dialects, compilers and operating systems. A configuration script lets users choose what underlying library to use (PIM, ISO, POSIX or vendor library). The choices depend on the dialect, the compiler and operating system.

As I am implementing the portability layer for use with the ISO library underneath, in particular a procedure that gets the size of a file, the ISO library type FilePos is giving me some headache.

I need to be able to do arithmetic operations on values of type FilePos in order to determine whether a value returned by RndFile.EndPos() would overflow type FileSize defined by my portability layer which is either CARDINAL or LONGINT depending on environment and configuration. If it does, I set a status SizeOverflow, which may happen when a compiler only supports 32 bit but produces code that runs on a 64 bit platform trying to get the file size of files larger 2 GB. A small price to pay for portability.

Anyway, I discovered that the p1 compiler does not permit arithmetic on values of type FilePos, nor does it permit conversion to another type. Astonishingly, this does not even appear to violate the ISO standard which defines type FilePos as an array of LOC of an implementation defined size. It does not seem to mandate that one can do arithmetic on values of the type.

Thus, when using the p1 compiler, I cannot convert the file size returned by RndFile.EndPos() nor could I check whether or not it would overflow my FileSize type. I had no choice but to open the file and read it byte by byte to the end while incrementing a counter in order to obtain a file size that is actually of any use. Very inefficient on larger files, but there seems to be no other way with p1's ISO library.

Now, I am wondering how many other ISO compilers, if any, suffer from the same silliness.

The operations I use can be seen in this function which checks whether an overflow would occur:

https://github.com/m2sf/m2pp/blob/master/src/imp/BasicFileSys/BasicFileSys.mw.mod#L192

if the test determines that no overflow would occur the value is simply converted using VAL().

https://github.com/m2sf/m2pp/blob/master/src/imp/BasicFileSys/BasicFileSys.mw.mod#L81


I would appreciate if list readers could check with whatever ISO compiler they have access to whether or not their compilers permit these arithmetic operations on values of type FilePos.

Many thanks in advance and apologies that this is not strictly a GM2 issue.

regards
benjamin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]