- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp]/*********************************************** This code returns the machine bit to the program bitinit ***********************************************/ #includefor my code in f90. I have interfaced it to fortran as#include #include int operating_system(void){ FILE *stream; char sys[8],*sysptr; int bit; sysptr = &sys[0]; sys[6] = 0x0; stream=popen("/bin/uname -m","r"); //stream=popen("file /sbin/init|awk '{print $3}'|cut -c1-2","r"); //printf("bit = %sn",stream); fread(sysptr,1,2,stream); pclose(stream); printf ("%sn",sysptr); /*bit=64; if ((strncmp(sysptr, "i686",2)==0)|| (strncmp(sysptr, "i386",4)==0)) bit=32;*/ return bit; } [/cpp]
[cpp] interface operating_system
function operating_system()result &
bind(C,name="operating_system")
use iso_c_binding
integer(C_INT) :: r
end function
end interface
[/cpp]
but the problem is if i want the c-code to return the value of uname, its not doing....what should i use instead of "void"? can you plz tell me so that i can print the output of uname in my fortran code? i am c-illeterate, and facing a lot of troubles.regards
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Roddur,
Youcould pass Stringinstead of intas yourfunction result, e.g.: In f90, define the interface as:
interface operating_system
function operating_system() result(string) &
bind(C,name="operating_system")
use iso_c_binding
CHARACTOER *8 :: string
end function
end interface
...
CHARACTER*8 unames
unames = operating_system();
write(*,*) unames
In c subprogram, define:
voidoperating_system(char * result, int * length)
{
...
// Copy output to result allocated at fortran
for (i=0; i
result = sysptr;
}
...
}
Note that the 2 parameters at Cfunction do not appear in the call statement; they are added by the compiler.
You can also refer to the intel compiler documentation onsection: "Programming Mixed Language - Handling Character Strings" for your reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have done this
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page