Silverfrost Forums

Welcome to our forums

Allocate on assignment for CHARACTER variables

20 Sep 2023 1:39 #30583

While trying to use the 'allocate on assignment' feature for CHARACTER variables implemented with FTN95 version 8.95, both following examples fail to compile with version 8.97.2. The error output seems to me contradictory.

PROGRAM Simon
IMPLICIT NONE
CHARACTER (LEN=:), ALLOCATABLE :: Says

CALL Sim('clap hands', Says)
WRITE(*,*) Says

CONTAINS

SUBROUTINE Sim(What, Out)
  IMPLICIT NONE
  CHARACTER (LEN=*), INTENT(IN):: What
  CHARACTER (LEN=:), INTENT(OUT), ALLOCATABLE :: Out
  Out = 'Simon says '//What
END SUBROUTINE Sim

END PROGRAM Simon

error 1234 - CHARACTER variable OUT must be ALLOCATABLE error 941 - OUT is a scalar dummy argument and so cannot be ALLOCATABLE

PROGRAM Simon
IMPLICIT NONE
CHARACTER (LEN=:), ALLOCATABLE :: Says

Says=Sim('clap hands')
WRITE(*,*) Says

CONTAINS

FUNCTION Sim(What) RESULT(Out)
  IMPLICIT NONE
  CHARACTER (LEN=*), INTENT(IN):: What
  CHARACTER (LEN=:), ALLOCATABLE :: Out
  Out = 'Simon says '//What
END FUNCTION Sim

END PROGRAM Simon

error 456 - ALLOCATABLE is an illegal attribute specifier for a RESULT variable such as (RESULT of SIMON~SIM)

20 Sep 2023 1:56 #30584

It looks like the use of CHARACTER variables in this way has not be considered.

I have added these to the list of missing features.

13 Aug 2024 8:48 #31467

This feature has now been added for the next release of FTN95 but only for x64.

13 Aug 2024 2:43 #31468

Paul Thank you very much for having added this feature.

20 Aug 2024 7:53 #31492

Paul I have tried both code samples with the new FTN95 version 9.04.0.0. The version with FUNCTION (2nd sample) works, thank you, the version with SUBROUTINE (1st sample) raises the following exception at runtime:

Unknown exception (c0000374) at address 7ff99e2ac399

Within file ntdll.dll In RtlIsZeroMemory at address 119 In RtlIsZeroMemory at address E3 In _misaligned_access at address 492 In _misaligned_access at address 77A In _misaligned_access at address AC65 In RtlGetCurrentServiceSessionId at address C95 In RtlFreeHeap at address 51 In _DEALLOCATE$ at address 69 Within file CLEARWIN64.DLL In ILT+1625(??$parse_integer_from_string_J_W$$T__crt_strtoxYA_JQEB_W$$THQEAU__crt_locale_pointersZ) at address 2 Within file Simon1.exe in SIMON~SIM at address 77

RAX = 394e54465c73746e RBX = 00000000c0000374 RCX = 5c73747365545c35 RDX = 652e316e6f6d6953 RBP = 0000000000405090 RSI = 0000000000000001 RDI = 00007ff99e317780 RSP = 000000000240fb00 R8 = 0000000000000000 R9 = 00007ff99d160000 R10 = 00007ff99d17aaa0 R11 = 0000000000620062 R12 = 0000000000000000 R13 = 0000000000000000 R14 = 0000000000000000 R15 = 0000000000000000

7ff99e2ac399) jmp 7ff99e2ac39b

20 Aug 2024 2:41 #31497

jlb

Thanks. I will have another go at this.

10 Sep 2024 7:18 #31539

This has now been added for the next release of FTN95

10 Sep 2024 4:37 #31541

Paul Thanks for having implemented this feature.

13 Sep 2024 12:10 #31547

I continued to play with this new feature. Compiling the following example

PROGRAM Simon
IMPLICIT NONE
CHARACTER (LEN=:), ALLOCATABLE :: Says

Says=Sim('clap hands')//' and '//Sim('sit down')
WRITE(*,*) Says

CONTAINS

FUNCTION Sim(What) RESULT(Out)
  IMPLICIT NONE
  CHARACTER (LEN=*), INTENT(IN):: What
  CHARACTER (LEN=:), ALLOCATABLE :: Out
  Out = 'Simon says '//What
END FUNCTION Sim

END PROGRAM Simon

fails with the error message

error 163 - Internal compiler error

The next example

PROGRAM Simon
IMPLICIT NONE
CHARACTER (LEN=:), ALLOCATABLE :: Says

Says=Sim('clap hands')
WRITE(*,*) Says

CONTAINS

FUNCTION Sim(What) RESULT(Out)
  IMPLICIT NONE
  CHARACTER (LEN=*), INTENT(IN):: What
  CHARACTER (LEN=:), ALLOCATABLE :: Out
  Out = 'Simon says nothing'
END FUNCTION Sim

END PROGRAM Simon

fails with the error message

error 773 - Variable of follows another operand (possible unexpected space?)

13 Sep 2024 12:44 #31549

jlb

Thank you for the feedback.

I think that your second sample will be relatively easy to fix. A fix for your first sample could prove to be very time consuming so the issue may end up on the back burner for some time.

There is quite a lot in 'allocate on assignment' that is proving to be a heavy drain on resources and one has to ask if the time would be better spent on other developments.

In the meantime FTN95 will require a more traditional approach in this context.

13 Sep 2024 1:22 #31550

Paul The whole thing started when I was curious about the 'allocate on assignment' feature for CHARACTER variables implemented in FTN95 version 8.95, more or less just for fun. Some of these attempts were not successful and are the origin of this thread. It was not my intention to commit development resources to such features and I fully understand that other priorities have to be set. Thanks as always for your patience and educational responses.

Please login to reply.