|
|
Up |
|
|
  |
Author: brubru Date: Apr 15, 2008 00:10
Hello,
I do not understand why I have this fatal error when compiling the
following test code with NAG f95
PROGRAM TST_STRING
CALL SUBSTR('HELLO THE WETHER IS NICE')
CALL SUBSTR('HELLO THE WETHER IS ')
CALL SUBSTR('HELLO THE WETHER ')
STOP
END
SUBROUTINE SUBSTR(STRNG)
CHARACTER(24) STRNG
WRITE(6,*) 'STRING=', STRNG
RETURN
END
Error: tst_string.f: Argument STRNG (no. 1) in reference to SUBSTR from
TST_STRING is too short a character string
[f95 error termination]
ccali05{bru}54:
|
| Show full article (0.85Kb) |
|
| | 14 Comments |
|
  |
Author: Arjen MarkusArjen Markus Date: Apr 15, 2008 00:28
On 15 apr, 09:10, bru wrote:
> Hello,
>
> I do not understand why I have this fatal error when compiling the
> following test code with NAG f95
>
> PROGRAM TST_STRING
>
> CALL SUBSTR('HELLO THE WETHER IS NICE')
> CALL SUBSTR('HELLO THE WETHER IS ')
> CALL SUBSTR('HELLO THE WETHER ')
> STOP
>
> END
> SUBROUTINE SUBSTR(STRNG)
> CHARACTER(24) STRNG
>
> WRITE(6,*) 'STRING=', STRNG
> RETURN
> ...
|
| Show full article (1.45Kb) |
|
| | no comments |
|
  |
Author: Gerry FordGerry Ford Date: Apr 15, 2008 01:03
> Hello,
>
> I do not understand why I have this fatal error when compiling the
> following test code with NAG f95
>
> PROGRAM TST_STRING
>
> CALL SUBSTR('HELLO THE WETHER IS NICE')
> CALL SUBSTR('HELLO THE WETHER IS ')
> CALL SUBSTR('HELLO THE WETHER ')
> STOP
>
> END
> SUBROUTINE SUBSTR(STRNG)
> CHARACTER(24) STRNG
>
> WRITE(6,*) 'STRING=', STRNG ...
|
| Show full article (2.18Kb) |
| no comments |
|
  |
Author: e p chandlere p chandler Date: Apr 15, 2008 05:19
On Apr 15, 3:10 am, bru wrote:
> Hello,
>
> I do not understand why I have this fatal error when compiling the
> following test code with NAG f95
>
> PROGRAM TST_STRING
>
> CALL SUBSTR('HELLO THE WETHER IS NICE')
> CALL SUBSTR('HELLO THE WETHER IS ')
> CALL SUBSTR('HELLO THE WETHER ')
> STOP
>
> END
> SUBROUTINE SUBSTR(STRNG)
> CHARACTER(24) STRNG
>
> WRITE(6,*) 'STRING=', STRNG
> RETURN
> ...
|
| Show full article (2.44Kb) |
| no comments |
|
  |
Author: brubru Date: Apr 15, 2008 06:28
e p chandler wrote:
> On Apr 15, 3:10 am, bru wrote:
>
>>Hello,
>>
>> I do not understand why I have this fatal error when compiling the
>>following test code with NAG f95
>>
>> PROGRAM TST_STRING
>>
>> CALL SUBSTR('HELLO THE WETHER IS NICE')
>> CALL SUBSTR('HELLO THE WETHER IS ')
>> CALL SUBSTR('HELLO THE WETHER ')
>> STOP
>>
>> END
>> SUBROUTINE SUBSTR(STRNG)
>> CHARACTER(24) STRNG
>>
>> WRITE(6,*) 'STRING=', STRNG ...
|
| Show full article (2.76Kb) |
| no comments |
|
  |
Author: e p chandlere p chandler Date: Apr 15, 2008 07:34
On Apr 15, 9:28 am, bru wrote:
> e p chandler wrote:
>> On Apr 15, 3:10 am, bru wrote:
>
>>>Hello,
>
>>> I do not understand why I have this fatal error when compiling the
>>>following test code with NAG f95
>
>>> PROGRAM TST_STRING
>
>>> CALL SUBSTR('HELLO THE WETHER IS NICE')
>>> CALL SUBSTR('HELLO THE WETHER IS ')
>>> CALL SUBSTR('HELLO THE WETHER ')
>>> STOP
>
>>> END
>>> SUBROUTINE SUBSTR(STRNG)
>>> CHARACTER(24) STRNG
> ...
|
| Show full article (3.21Kb) |
| no comments |
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: Apr 15, 2008 07:42
bru wrote:
(snip)
>>> CALL SUBSTR('HELLO THE WETHER ')
(snip)
>>> SUBROUTINE SUBSTR(STRNG)
>>> CHARACTER(24) STRNG
>>> WRITE(6,*) 'STRING=', STRNG
>>> Error: tst_string.f: Argument STRNG (no. 1) in reference to SUBSTR from
>>> TST_STRING is too short a character string
>>> [f95 error termination]
>>> ccali05{bru}54:
>>> The number of characters is less or equal 24 !!!!!
>>> Nevertheless it runs ok with Sun f90, f77; ifort; pgf95 pgf77
>>> ; g95,g77
>>> (for fortran 77 I put CHARACTER*24)
(snip)
>> 1. Compilers and run time libraries are not required to detect this
>> type of argument mismatch.
(snip)
|
| Show full article (1.35Kb) |
| no comments |
|
  |
Author: nospamnospam Date: Apr 15, 2008 08:41
e p chandler juno.com> wrote:
> But CHARACTER(*) is not an ARRAY, so some suggest to use
>
> CHARACTER(len=*) instead.
Just to elaborate on a potential wording confusion. The len= form isn't
an array either. These two forms are exactly equivalent. The only
difference is in how it looks. Presumably the suggestion is based on
some people thinking that the form without len= looks like an array.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
| |
| no comments |
|
  |
Author: nospamnospam Date: Apr 15, 2008 08:41
glen herrmannsfeldt ugcs.caltech.edu> wrote:
> Note that you could have CHARACTER*24 in the subroutine, but only
> reference the first few characters. Some will report a warning,
> with the assumption that you only reference characters that are
> actually in the actual argument. I believe it is technically
> illegal, but it will work with most systems.
Some will report not just a warning, but an error. In particular, I am
confident that the reported error would still be there if only the first
few characters are referenced.
I strongly disagree with the comment about it being "technically"
illegal and the implication that it is ok to do. It is just plain
illegal. It is plausible that it might result in memory corruption from
copy-out of all 24 characters.
|
| Show full article (2.40Kb) |
| no comments |
|
  |
|
|
  |
Author: James Van BuskirkJames Van Buskirk Date: Apr 15, 2008 09:02
"Richard Maine" wrote in message
news:1iffj75.93qwvchakv7kN%%nospam@see.signature...
> Just don't do this. Period. Don't try to figure out what variants you
> might or might not be able to get by with in some compilers. Just don't
> do it at all. As Arjen suggested, use character(*) for dummy arguments.
> In my opinion, it is almost always a bad idea to use any length other
> than * for a character dummy argument. Non-* lengths open possibilities
> for error (which I have personally been bitten by). Compilers don't
> necessarily (or even usually) catch the error, so it isn't as though
> using a non-* length is good for catching the error if you intended the
> length to be some particular value and accidentally got one wrong; that
> can result in confusing run-time errors.
The above applies if the dummy argument is a scalar. If the dummy
argument is an array, the rules of sequence association give you
ways to slice and dice the actual argument creatively, or to make
new and surprising errors if it happens unintentionally. But the
rule that the sequence you get from the actual argumment must be
at least as long as the dummy argument, or the part of the dummy
argument that gets used if assumed-size, still holds.
|
| Show full article (1.37Kb) |
| no comments |
|
|
|
|