[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-fortran
Subject:    Re: No alignment in derived types wished
From:       GD <gdoublon () gmail ! com>
Date:       2012-07-18 8:06:13
Message-ID: 50066E75.2030505 () gmail ! com
[Download RAW message or body]

Hello,

> EQUIVALENCE is always a disaster area, and the modern replacement is the
> TRANSFER intrinsic, but even that should be avoided (because both it and
> "packed" are extremely dangerous).

Thank you for your advice.
I did not know the TRANSFER function, I will certainly use it.

> If you can, it is far better to work out the format you need before
> you read it; ADVANCE='NO' or the POS= qualifier may help here.

As far as I understand the ADVANCE='NO' is for text files only? I try to 
read a binary file that was generated by a program written in Borland 
Pascal, it has fixed length records. Each record is a mixture of 
integer*1 and integer*2. I cannot figure out how to directly read it 
with a derived type, e.g.:
type Trec
   sequence
   integer*1 var1
   integer*2 var2
end type Trec
type (Trec) record
Due to alignment performed by gfortran, this derived type cannot be used.

Regards,
George

On Jul 17 2012, N.M. Maclaren wrote:
> On Jul 17 2012, Tobias Burnus wrote:
>> On 07/17/2012 11:44 AM, GD wrote:
>>> How can I deactivate alignment in derived types?
>>
>> I think that's currently not possible. Fortran (as C) doesn't provide
>> such a possibility and for gfortran no such extension has been
>> implemented.
>>
>> For GCC's C/C++ compiler, you can use the "packed" attribute, as
>> described at http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
>>
>> It is planned to extend this support to GCC's gfortran using
>> directives [1], but it requires some work [2].
>
> However, it is far better not to do it that way, anyway, as it will
> work on only some systems, and with only some options.  EQUIVALENCE
> is always a disaster area, and the modern replacement is the TRANSFER
> intrinsic, but even that should be avoided (because both it and "packed"
> are extremely dangerous).
>
> If you can, it is far better to work out the format you need before
> you read it; ADVANCE='NO' or the POS= qualifier may help here.
>
> The above is not specific to gfortran, but applies to all Fortran
> compilers.
>
>
> Regards,
> Nick Maclaren.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic