J3/03-254 Date: 29 September 2003 To: J3 From: Aleksandar Donev Subject: Post Fortran 2003: Adding MOLD to ALLOCATE ______________________________________ Summary ______________________________________ A MOLD argument should be added to ALLOCATE similar to the SOURCE argument, which would only give the type of the allocated data, but not the contents. This would allow one to allocate an array of a given type given only a scalar of that type, which is needed to design custom allocators for various dynamic data structures. ______________________________________ Motivation ______________________________________ It is sometimes desired to allocate a new object of unknown dynamic type, and rather then clone the contents of another object, perform default initialization on the newly allocated object. This is very similar to the "new" operator in C++. ______________________________________ Proposal ______________________________________ I propose to add a MOLD argument to ALLOCATE, with the same semantics as SOURCE, but without the copy of the contents of the mold variable. The mold variable will thus simply serve as a type template for the allocation, and can be a scalar even if the allocate-object is an array.