Hi pals, I tried to implement my code from FORTRAN to C, but I found a problem, how can I call a subroutine in C, I saw that I could use the command VOID but Im not sure, could you explain me this please
thx
Hi pals, I tried to implement my code from FORTRAN to C, but I found a problem, how can I call a subroutine in C, I saw that I could use the command VOID but Im not sure, could you explain me this please
thx
It has been long since I have written fortran, and I never was really advanced in it...
But I guess subroutines were close to functions in C (or close to using 'goto' statement - which is not good way in C - it makes larger codes a mess).
But I doubt no one will give you detailed description about functions in C. I suggest you'll google some really basic C tutorial, and experiment with creating functions. You should also pay attention to "pass by reference" Vs. "pass by value" issues in C.
You can then come back, and ask a bit more specific questions if needed.
Obsession to networking and protocols made me cook up these:
NSN - Network Status Notifier
epb - Ethernet Packet Bombardier
T.H.O.N.G.S - Textmode Helper On Network Getting Sniffed
Nibbles - console UDP print listener/filter + something else
Feel free to try, comment and improve =)
A fortran subroutine is, in C, a function with no return value, which is a "void" function.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
So I can use VOID in C as I use subroutine in Fortran right
Yes, but C is case-sensitive, so "VOID" is not the same as "void".
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
well some problem trying to implement my code from fortran to C with void somebody could help me
Code:void contour (float f[][],float x[],float y[],int jmax, int imax) { for(j=1;j<=jmax;j++) { f[1][j]=ui*x[1]; f[imax][j]=ui*x[imax]; } for(i=1;i<=imax;i++) { f[i][jmax]=ui*x[i]; if((i>=il) && (i<=it)) f[i][1]=f[i][2]-0.1*(y[2]-y[1])*(1.0-2*x[i]); else f[i][1]=f[i][2]; }// end contour ()
Ok, so in C, you have to SPECIFY the size of all but the right-most array size - or use a single-dimension array.
You also must start array indices at 0, not 1. So array[imax] will not work, probably.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
even in void as in the main I need to specify the size of the array?
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
'void' in C is used a couple of ways:
1 - To indicate that the function will not return a value.2 - To indicate that a function takes no arguments (is passed nothing).Code:void fun1( int x ) { printf( "x + 1 is %d\n", x + 1 ); }3 - To declare a "universal" datatype.Code:int fun2( void ) { printf( "This function takes no parameters, but returns something!\n" ); return 0; }You can assign any type to a void pointer, and it will keep tabs on it for you. But to get back what you're pointing at, you need to reference that type implicitly.Code:void *vptr; int x; char c; vptr = &x; ... vptr = &c;
You can also use it as a cast to disregard return values, but you usually don't need to do that.
Quzah.
Hope is the first step on the road to disappointment.
The phrase is "couldn't care less". Could care less means that it does care, and it could care less than it currently does, but doesn't for some reason...
For the record, I don't care as much what the compiler thinks, as much as I care what the language defines. Anyway, I'm clear on what it is you're trying to say. If you're saying that when you call a function which takes no parameters, you don't have to specify void:Then I agree. When you call a function which takes no arguments, you do not have to provide arguments. That's sort of the whole point.Code:void fun( void ) { ... } ... fun( );
Quzah.
Hope is the first step on the road to disappointment.
The point is / was that this...
The "void" must be in the prototype to tell the compiler that function takes no arguments. Sure, if you only provide a definition, then you must use void in the parameter list.Code:void fun(void); void fun() { // blah }
This trickery allows this sort of stuff to compile:
Code:void fun(); // Unspecified number of args void fun(int arg1, int arg2) { // blah }
Void specifies that there are no arguments. Empty specifies that there are an unspecified number of arguments. There's a difference. And since I wasn't talking about having an unspecified number of arguments, it's not relevant to the discussion of void really. Again, void is specifically saying that there will be no arguments.
Quzah.
Hope is the first step on the road to disappointment.
I merely want to make it clear that this works:
This works:Code:void foo(void); void foo() { } int main() { foo(); }
And this works:Code:void foo(void); void foo(void) { } int main() { foo(); }
In all of them, foo takes no arguments and the compiler will complain if you try.Code:void foo(void) { } int main() { foo(); }