Path: news.mathworks.com!newsfeed-00.mathworks.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: nospam@see.signature (Richard Maine)
Newsgroups: comp.lang.fortran,comp.soft-sys.matlab
Subject: Re: Fortran formatted read problem (for matlab MEX file)
Date: Fri, 6 Nov 2009 12:03:53 -0800
Lines: 50
Message-ID: <1j8rcld.jsu21v1rn5saeN%nospam@see.signature>
References: <7af025a1-6d40-4458-aab0-35bc43418c00@i12g2000prg.googlegroups.com> <hd1sg5$u5k$1@news.eternal-september.org> <d039a82a-256d-411d-a100-2b07c196cb0f@2g2000prl.googlegroups.com>
X-Trace: individual.net 565YF5uu0UYdE220FwXkswL2p27ofVWx1ygAeUbX+/xafhVigN
X-Orig-Path: nospam
Cancel-Lock: sha1:ZK2V40Q6ozg1HJ3LmGUGUm24+Gs=
User-Agent: MacSOUP/2.8.2 (Mac OS X version 10.6.1 (x86))
Xref: news.mathworks.com comp.lang.fortran:213339 comp.soft-sys.matlab:583103


Nathan <ngreco32@gmail.com> wrote:

> Some of my variables seem to just appear out of nowhere, with no data
> type declaration... Could this be a problem?

Yes, very often. That's called implicit typing. It is a common source of
errors for multiple reasons.

If you allow implicit typing, then that means simple typos are likely to
get misinterpreted as new different variables instead of flagged as
errors. This one is quite common.

Also, implicit typing encourages sloppy thinking. This is even more the
case if you think of it as variables just appearing "out of nowhere."
Data type is important. You should think about the appropriate data type
for each and every variable in a program. Sometimes it doesn't take very
much thought at all. But it sure shouldn't be that "the compiler will
take care of making everything right"; it should be your deliberate
choice. Explicitly declaring the type of a variable is at least an
encouragement to think briefly whether it is the appropriate type. It is
certainly so that people are capable of getting into such an automated
mode that writing a declaration doesn't necessarily trigger any thought
about whether it is the appropriate declaration, but at least it serves
as an encouragement.

Implicit typing does work. It is not a problem in the sense that it
necessarily means the code isn't correct. It is just a problem in that
it is error prone. It also makes the code hard to understand when
reading because if you don't see a declaration, you can't tell whether
that means the variable is implicitly declared or that its declaration
is someplace you haven't looked yet (possibly in a separate include file
or module).

Putting an

  IMPLICIT NONE

statement in each subroutine will turn off implicit typing. You have to
put that statement near the beginning of the subroutine, after the
subroutine statement, but before almost anything else. (USE statements
do come earlier if you have any of them).

Though if you do that for code that was written using implicit typing,
it will probably generate a lot of error messages at first until you add
declarations for everything.

-- 
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain