- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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));
}
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));
}
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
%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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the advice, I'll do that.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page