This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: g77-alpha binary file BACKSPACE does not work


I wrote:

[ Showing part of f_back in egcs/gcc/f/runtime/libI77/backspace.c ]

>48    {       (void) fseek(b->ufd,-(long)sizeof(int),SEEK_CUR);
>49            (void) fread((char *)&n,sizeof(int),1,b->ufd);
>50            (void) fseek(b->ufd,-(long)n-2*sizeof(int),SEEK_CUR);

>Note that n == 0, and therefore the "seek back" isn't effective.   
>Could someone with more experience on Linux/Alpha join in to tell us  
>the exact argument signature of fseek, as I suspect that the cast  
>to long (64-bits on Alpha) might be wrong ...

and Richard Henderson replied:

>  extern int fseek(FILE* fp, long int offset, int whence);

>  But that shouldn't matter with small numbers, since they
>  are always sign extended to 64 bits across the function
>  call anyway.

Ah, because the argument slots are 64 bits ?

>  What I don't understand is the semantics of `backspace'.
>  From this code we are backing up a number of bytes
>  proportional to the last integer written to the file.
>  This makes no sense to me.

Hmm, yes, I better explain the format of unformatted :-) files here  
then, because the answer to this question is actually quite  
straightforward.

A Fortran unformatted sequential file has - on most Unix systems -  
the following structure:

{ [ 4 byte record length of following record ] [ the record itself  
] [ 4 byte length of preceding record ] }*

The reason for this format is:

1. The Standard allows reading the initial part of a record.  Without
   the first record length, you would loose track of your position in
   the file.

2. The Standard allows backspacing over records; to be able to do
   that, you have to know the length of the preceding record.

HTH,
Toon.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]