Passing string constants

Passing string constants

We have legacy code (HP 1000 Fortran) that includes many instances of the following:

call sub('abc')


subroutine sub(I)
integer*2 I(2)
! I(1) should contain 0x6261 and I(2) should contain 0x0063

Is there an elegant way using attributes to make this work in CVF?

The present solution we have is a pre-compiler that converts the above code to

character*3 $c1
integer*2 $t1
equivalence ($c1, $t1)
data $c1 /'abc'/


call sub($t1)


This works but I wonder if there is a cleaner way to do it.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

There is an easier way, though I'm sure you understand that your current code is incorrect. (Yes, it works on a lot of compilers, but it's still wrong..)

Anyway - there are two CVF options you need to change to accomodate this coding practice. Both can be found under Project..Settings..Fortran..External Procedures.

Change Argument Passing Convention to "C, by Ref".
Change String Length Argument Passing to "After all Args"

If you are using the command line, the switches to add are: /iface:cref /iface:nomixed_str_len_arg

Do a Build..Rebuild All.


Retired 12/31/2016

Thanks -- we'll try this.

Leave a Comment

Please sign in to add a comment. Not a member? Join today