...

View Full Version : Global variables in FORTRAN



Spookster
01-21-2003, 04:44 AM
Ok where are all the old folks at? Yeah you old timers that grew up learning Fortran back in the 50's. :)

How are global variables in Fortran declared? Do you just declare them outside any functions for them to be global or is there some keyword I need to use?

Spookster
01-21-2003, 04:53 AM
I'm using Fortran77 by the way.

Spookster
01-21-2003, 06:07 AM
Ok after much digging I found the answer. Using the COMMON block statement allows one to share variables among different functions/subroutines:

http://www.obliquity.com/computer/fortran/common.html

Spookster
01-23-2003, 09:28 AM
And by the way I just spent the last week learning Fortran so if anybody has questions on Fortran, ask away.

Next week I will learn COBOL, then the next week Shell scripting, then Prolog, then LISP.

CRASH_OVERRIDE
01-25-2003, 01:18 AM
Why would you need to learn all of those languages- I thought they were ancient.:D

Spookster
01-26-2003, 12:33 AM
Yes they are all pretty old. Especially Fortran. Why learn them?

1. These old languages were the basis for all future languages. Learning those will make learning other newer languages easier.

2. Many businesses do still use languages like Fortran and Cobol. Especially Cobol. Lisp is the most widely used language for AI.

3. They are all required for my bachelors degree in computer science.

:)

scroots
01-26-2003, 01:09 PM
Also there is a shortage of cobol programmers so if you can do it you can earn big bucks.

scroots

ScottInTexas
01-27-2003, 09:59 PM
Don't forget Pascal, Forth and Ada.

I mean, we wouldn't want to leave anyone out.

When I took Fortran IV I was also learning Compiled Basic on the new Vax 11/780 (Super hot stuff!), and I'm not that old! Even so, I couldn't have given you the answer without diggin through my books or old programs.

Scott

ALMAR
01-10-2007, 06:05 PM
Ok after much digging I found the answer. Using the COMMON block statement allows one to share variables among different functions/subroutines:

http://www.obliquity.com/computer/fortran/common.html

Hey there!
I've found your comment by browsing i-net.
Problem is the next: when I making main program in Fortran by that manner for defining common blocks it conflicts with the _main() C++ program.

I trying to make mixed C++\Fortran program, for usage old Fortran modules. There no problem with functions an local variables, but in the case of global variables - need help!

DavidB
01-16-2007, 04:37 AM
And by the way I just spent the last week learning Fortran so if anybody has questions on Fortran, ask away.


This post is pretty old; is your offer still open?

I often translate FORTRAN programs into C++ and Javascript. To help me understand what a program does, I have downloaded and installed the OpenWATCOM compiler. One small piece of code I have recently come across has me puzzled: the FORTRAN 77 program uses a variable "L" without declaring it anywhere. Does FORTRAN default undeclared variables to a particular type?

Regards.


David

felgall
01-16-2007, 09:50 PM
Fortran defaults variables starting with I, J, K, L, and M to integer and everything else to float. That is why I is the variable usually chosen to control loops since it was the shortest variable name to use as a loop control that comes earliest in the alphabet.

badddad
02-24-2012, 09:32 PM
Yeah but why were they chosen like that in the first place? Because those letters (as lower case subscripts) are used in mathematics all the time! Implementing mathematical algorithms was the design principle behind FORmula TRANslator in the first place :cool:

felgall
02-24-2012, 09:43 PM
Also there is a shortage of cobol programmers so if you can do it you can earn big bucks.

Only if you live in India and only relative to what other Indians earn. All the CoBOL jobs went to India about ten years ago when companies realised how much cheaper it was. They had employed the Indians to work on Y2K in order to get the necessary hundreds of extra staff needed for that project at an affordable price and once it was finished it was basically the local staff who were let go and the Indians retained to maintain the systems.

The more programming languages that you know the easier it is to learn additional similar languages and to make sens of code in languages that you don't know. After learning the first language in any given programming style it becomes easier to learn additional programs that use that style. If is the first procedure based, object oriented, rules based etc language that is the hardest to learn. Just to know one of each type of language would mean learning a dozen or more different languages. I know languages in each of the three styles mentioned but not any of the others. Fortran was the first language I learnt - back in the mid 70s before I had access to a computer.

tracknut
02-24-2012, 10:04 PM
I can certainly attest to the "new type of language" issue. Some of the hardest languages I ever learned were SNOBOL (string oriented), APL (sort of a mathematical symbol language), LISP (a language for people fond of parentheses), and JAM (to program the Xerox Star, with a stack as the only memory available).

For me at least, any of these were harder than C or Assembly, because they were different enough that normal assumptions about programming didn't always apply.

Dave



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum