val() error with ifort 8

val() error with ifort 8

Hi all,
I've got a pb in mixing C and fortran with %val().
Here a simple example :

test-c.c

void fort_rout(int,int*);

int
main(int argc,char *argv[])
{
int n;
int *vect=NULL;

n=100; /* just to fix the size */
vect=(int*)calloc(n,sizeof(int));

}

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

Sorry gone to fast...

the end of the example

void fort_rout(int,int*);

int
main(int argc,char *argv[])
{
int n;
int *vect=NULL;

n=100; /* just to fix the size */
vect=(int*)calloc(n,sizeof(int));
/* Call the fortran routine */
fort_rout(n,vect);
...
}

test-f.f

subroutine fort_rout(%val(n),vect)
integer n
integer vect(n)

integer i

do i=1,n
vect(i)=...
enddo
end

This mixing work fine with ifc 7.1 and icc, but got a syntax
error with ifort 8.

Any idea ?

One more thing is that I would like NOT to use the
!DEC$ ATTRIBUTES rule in order to keep the compatibility with other compilers like g77.
Tx for response

%val worked in the subroutine statement in 7.1? Very, very strange... I'll have to try it - I am somewhat skeptical.

If you want compatibility, then you have to arrange to pass the arguments from C by address rather than by value. This would work for g77 as well.

Steve - Intel Developer Support

Your are right, passing all by address is just fine.
The idea is to pass from C to fortran : by address things
that have to by changed by fortran routines and by value
things that must stay constant throught the fortran process.

Well, you can't do that in a portable way. If you want portability, pass by address always. Otherwise, use the !DEC$ ATTRIBUTES VALUE directive and understand that you'll have to change this with different compilers. Some compilers may not support a Fortran routine accepting arguments by value.

Steve - Intel Developer Support

Thanks for the advice, I'll do that.

Leave a Comment

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