Re: derived types with parameter keyword



wim <wim.van.hoydonck@xxxxxxxxx> wrote:

ifort complains along these lines:
m_unit.f90(21): error #6355: This binary operation is invalid for this
data type.
type(unit_t) , parameter :: velocity_unit = length_unit /
time_unit ! unit_t(0,1,-1)

where unit_t is a derived type with a defined operation for "/".

Any reason why this is not allowed/doesn't work?

I could quote the standard-speak to show what restrictions are violated,
but it can be explained more simply than that.

Parameters are intended to be computable at compile time. (The standard
doesn't use that terminology, but that's the idea). Your defined
operation involves executing a user-written procedure. You can't execute
user-written procedures at compile time. You have to wait until after
they have been compiled.

This isn't anything specific to derived types. You just happen to be
using a derived-type defined operation to reference the procedure. If
you tried any other way of referencing a user-written procedure to
define a parameter, that wouldn't work either.

Yes, one could in theory have some kind of compilation system that
allowed such things, but that would be much more complicated than the
relatively simple model of separation of compilation and execution that
Fortran and many other languages use.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
.



Relevant Pages

  • Re: derived types with parameter keyword
    ... I could quote the standard-speak to show what restrictions are violated, ... Parameters are intended to be computable at compile time. ... operation involves executing a user-written procedure. ... attention to the execution model in fortran. ...
    (comp.lang.fortran)
  • Re: Calling on Methods and Properties within Worksheet Modules
    ... The only reason why I can think of doing that, the Object data type is ... VB.NET base code, ... to other limitations and the lack of being able to bind at compile time. ... Declare l_wsh As Object ' note not as worksheet ...
    (microsoft.public.excel.programming)
  • Meta-literals
    ... are exact in Decimal and not exact in float. ... Unfortunately it is not very easy to access the Decimal data type. ... With Python 3000 major changes to the language are carried out anyway. ... compile time, and marshal the evaluated value into the *.pyc file. ...
    (comp.lang.python)
  • Re: REXML ... performance & memory usage ...
    ... It uses libxml2 for the parsing, and as such is quite speedy. ... I had to make two fixes to the source to get things to compile ... with the va_list data type without it. ...
    (comp.lang.ruby)
  • A few basic c++ questions regarding 64 bit programming
    ... Will compiling on xp64 solve this? ... I looked but don't see a 64 bit data type ... I know Visual studio 2003 can compile for 64 when certain flags are set so I ...
    (microsoft.public.vstudio.general)

Loading