- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I am getting this error in one of my Fortran to C++ interfaces. Any ideas based on the declarations and interface code posted in the attached file?
- Etiquetas:
- Intel® Fortran Compiler
Enlace copiado
6 Respuestas
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
The "default" calling convention on the C side is to pass by value. Fortran's default for BIND(C) is pass by reference (pass a pointer to the variable).
Your C routine has a whole heap of int parameters being passed by value. To change the Fortran side to match the C side you then need a whole heap of VALUE attributes on the integer arguments in the interface body (note that the float/REAL argument is a pointer in the C declaration, so things match for that one).
INTEGER(C_INT), VALUE :: NBOX
etc...
(It's important to understand this aspect of calling C - if its not clear then ask more questions/do some background searches yourself.)
Your C routine has a whole heap of int parameters being passed by value. To change the Fortran side to match the C side you then need a whole heap of VALUE attributes on the integer arguments in the interface body (note that the float/REAL argument is a pointer in the C declaration, so things match for that one).
INTEGER(C_INT), VALUE :: NBOX
etc...
(It's important to understand this aspect of calling C - if its not clear then ask more questions/do some background searches yourself.)
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Thanks Ian. I'll make a note of the default calling convention on C side.
So by default C receives variables from Fortran and passes variables to Fortran by value while by default Fortran will receive and pass variables by reference.
Are REAL/float variable declarations always pointers in C?
So by default C receives variables from Fortran and passes variables to Fortran by value while by default Fortran will receive and pass variables by reference.
Are REAL/float variable declarations always pointers in C?
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
iso_c_binding in ifort works the same as in public postings. The default on the Fortran side is to pass a pointer value, so it looks like by reference on the C side, in fact ought to work with the C++ reference extension of extern "C". To receive a value on the C side, you add the value specifier on the Fortran side. It's the same with integer or real.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Hi Tim, what do you mean that the binding works the same as in "public postings"?
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
There are several good articles on iso_c_binding you will find in a browser search. Any article about standard Fortran is good.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Thanks. I've been reading up a bit online as I code.

Responder
Opciones de temas
- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla