-
Topic author
joukj
- Master
- Posts: 184
- Joined: Thu Aug 27, 2020 5:50 am
- Reputation: 0
-
Status:
Offline
Post
by joukj » Thu Nov 16, 2023 9:17 am
Hi I get this:
Code: Select all
rumba-jj) f90/vers
VSI Fortran x86-64 X8.5-007 (GEM 50XBD) on OpenVMS x86_64 V9.2-1
rumba-jj) ty test.f90
program test
real aap
integer ceil
aap =11.0
write(*,*) ceil( aap / 8.0 )
end
rumba-jj) ty ceil.f90
integer function ceil( realvar )
!
ceil = int( realvar )
if ( float( ceil ) .ne. realvar ) then
if ( realvar .gt. 0.0 ) then
ceil = ceil + 1
else
ceil = ceil - 1
end if
end if
!
return
end
rumba-jj) f90 test.f90
rumba-jj) f90 ceil.f90
rumba-jj) link test,ceil
rumba-jj) run test
2
rumba-jj) f90/name=lower test.f90
rumba-jj) f90/name=lower ceil.f90
rumba-jj) link test,ceil
rumba-jj) run test
0
rumba-jj) f90/name=lower/noop test.f90
rumba-jj) f90/name=lower/noop ceil.f90
rumba-jj) link test,ceil
rumba-jj) run test
1068498945
Obvious the right result is 2 but I get 2 different wrong results if compiled wih /name=lower.
Jouk
Last edited by
joukj on Thu Nov 16, 2023 9:19 am, edited 1 time in total.
-
arne_v
- Master
- Posts: 374
- Joined: Fri Apr 17, 2020 7:31 pm
- Reputation: 0
- Location: Rhode Island, USA
-
Status:
Offline
-
Contact:
Post
by arne_v » Thu Nov 16, 2023 8:17 pm
It looks like the "weird results" comes from calling math$ceil_t instead of your ceil.
The code works fine if ceil is renamed to myceil.
It must be some sort of bug that lowercasing causes it to switch from your ceil to math$ceil.
-
Topic author
joukj
- Master
- Posts: 184
- Joined: Thu Aug 27, 2020 5:50 am
- Reputation: 0
-
Status:
Offline
Post
by joukj » Fri Nov 17, 2023 2:39 am
Thanks
It means that now all C-functions can be called directly from Fortran? I just tested a few and all seem to work:
Code: Select all
rumba-jj) ty test.f90
program test
real*8 aap
real*8 , external :: ceil
integer strlen
integer*8 getpid
character*8 str
str = '12345' // char(0)
aap =11.7
write(*,*) ceil( %val(aap / 8.0 ))
write(*,*) getpid()
write(*,*) strlen( %ref( str ) )
end
17-NOV-2023 08:36:43
rumba-jj) f90/name=lower test
rumba-jj) link test
rumba-jj) run test
2.00000000000000
538969400
5
-
arne_v
- Master
- Posts: 374
- Joined: Fri Apr 17, 2020 7:31 pm
- Reputation: 0
- Location: Rhode Island, USA
-
Status:
Offline
-
Contact:
Post
by arne_v » Fri Nov 17, 2023 8:54 am
It has always been possible to call a C function from Fortran, but it seems like C functions has become Fortran functions now - since the Fortran compiler adds prefix and suffix to the name. If they are lowercase that is.
It could be a nice feature I guess.
But:
1) it should be documented
2) there should be a warning/error when compiling a conflicting name
3) I believe that it should be done for both lowercase and uppercase
Looking forward to hear VSI explain what they have done and what they want to do.
-
jreagan
- VSI Expert
-
Master
- Posts: 145
- Joined: Tue Dec 01, 2020 8:40 am
- Reputation: 0
-
Status:
Offline
Post
by jreagan » Fri Nov 17, 2023 12:47 pm
We'll discuss it and document it better. The trouble here is that LLVM sometimes wants to insert a call to ceil as part of a code transformation and needed to know the name of the routine. The internal table had "ceil" in it and we changed it to "math$ceil_t". I think the code in LLVM decided that ALL calls to ceil need to be mapped to math$ceil_t.
-
Topic author
joukj
- Master
- Posts: 184
- Joined: Thu Aug 27, 2020 5:50 am
- Reputation: 0
-
Status:
Offline
Post
by joukj » Mon Nov 20, 2023 3:28 am
I solved the problem by putting ceil in a module. It was in a library anyway and I was transforming all the entries to accept different arguments (in theis caese al*4,*8&*16) anyway.
calling the crl-routines directly from fortran without a wrapper may be a nice feature to have.
Jouk
-
Topic author
joukj
- Master
- Posts: 184
- Joined: Thu Aug 27, 2020 5:50 am
- Reputation: 0
-
Status:
Offline
Post
by joukj » Mon Jan 29, 2024 3:02 am
Solved in the latest Fortran compiler.