Fortran Fortran: Problems with dummy variables in functions

AI Thread Summary
The discussion revolves around a programming issue where a function is ignoring the first of three dummy variables, leading to a segmentation fault when attempting to use the third variable. The user initially calls the function with three parameters but encounters problems until they add an extra dummy variable, which resolves the issue without clear explanation. The user expresses frustration and seeks help, mentioning attempts to inform the compiler about the parameters being arrays rather than scalars, which did not resolve the problem. They later report success after converting the function to a subroutine, noting that subroutines may handle arrays better. However, there is a clarification that the distinction between functions and subroutines lies in their return behavior, with functions returning values and subroutines performing actions without returning values.
thefury
Messages
7
Reaction score
0
I have a function that seems to be ignoring the first of 3 dummy variables. These variables are arrays with integer elements, should that be important.

For example, the call in the program is something like:
A = F(b,c,d)

and this transfers control to a function F, that is similar to:

Code:
FUNCTION F (x,y,z) RESULT (R)

  IMPLICIT NONE
  INTEGER :: x, y, z, R

...
operations
...

END FUNCTION F1

x takes on the value of c, y takes on the value of d and any call to use z produces a segmentation fault.

Adding another dummy variable before b (i.e. A=F(e,b,d,c) ) solves the problem with seemingly no bad effects but I'd rather have a correct function instead!

This has been bugging me for about 2 hours now and any help would be appreciated!
 
Technology news on Phys.org
You need to inform the compiler that the formal parameters x, y, and z are arrays rather than scalar values.
 
I tried that too but with no success. Thank you for the suggestion.

I have it working sensibly now, but I turned my function into a subroutine. I gather from what I've read that subroutines are somehow more adept at dealing with arrays.
 
thefury said:
I tried that too but with no success. Thank you for the suggestion.

I have it working sensibly now, but I turned my function into a subroutine. I gather from what I've read that subroutines are somehow more adept at dealing with arrays.
I don't think so. Subroutines and functions are two types of subprograms. The basic difference between the two is that a function returns some value while a subroutine causes something to happen and doesn't return a value.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...

Similar threads

Replies
8
Views
2K
Replies
12
Views
1K
Replies
59
Views
11K
Replies
3
Views
2K
Replies
3
Views
2K
Replies
8
Views
4K
Replies
12
Views
3K
Back
Top