Re: F$TYPE of space is INTEGER (392 Views)
Reply
Occasional Advisor
Lester_Dreckow
Posts: 9
Registered: ‎08-31-2011
Message 1 of 8 (520 Views)

F$TYPE of space is INTEGER

Who would have thought that f$type of a symbol containing a space is considered to be an integer!  It looks more like a string.  Oh well, I guess we can code around it.

 

$ s = " "
$ t = f$type(s)
$ show symbol %
  S = " "
  T = "INTEGER"
$

 

But the empty string is a string.


$ s = ""
$ t = f$type(s)
$ show symbol %
  S = ""
  T = "STRING"
$
$ tcpip show version

  HP TCP/IP Services for OpenVMS Industry Standard 64 Version V5.6 - ECO 5
  on an HP rx3600  (1.59GHz/9.0MB) running OpenVMS V8.3-1H1

$

 

Cheers,

Lester

Honored Contributor
Hein van den Heuvel
Posts: 6,588
Registered: ‎05-19-2003
Message 2 of 8 (506 Views)

Re: F$TYPE of space is INTEGER

That's a bug/inconsistency....

 

fwiw,

Hein.

 

DCL

LEXICON

.. F$TYPE

      TSTL R1 ;NULL STRING?
     BEQL 10$ ;YES, THEN BRANCH
:

      JSB DCL$CNVASCBIN ;CONVERT THE STRING TO DECIMAL

      TSTL R0 ; Test return status
       BEQL 150$ ;IF SUCCESSFUL, THEN INTEGER

; SYMBOL IS A STRING
     10$: MOVAB STRING,R2 ;SETUP RETURN DESCRIPTOR

 

 

CONVERT

...DCL$CNVASCBIN:: ; CONVERT IN SPECIFIED RADIX
:

      BSBW DCL$TRIM ; TRIM AND UPCASE THE STRING

:

      CLRL-(SP); SAVE ROOM FOR  "NUMBER SEEN" FLAG

:

      MOVL R2,R0 ; TEST FOR ZERO LENGTH STRING

      BEQL 70$ ; IF IT IS THE NULL STRING-RETURN ZERO

      70$:...

      BLBC (SP)+,90$ ; IF A NUMBER SEEN, FLAG OK AS IS
      MOVL #1,R0 ; IF NO NUMBER SEEN, UNCONDITIONALLY SET TO FAILURE

      90$: RSB ; BACK TO THE CALLER

 

 

Trusted Contributor
John McL
Posts: 280
Registered: ‎02-24-2008
Message 3 of 8 (450 Views)

Re: F$TYPE of space is INTEGER

Never take even simple claims at face value.  I just tested the sequence described here and got different ...

 

$ s = ""
$ t = f$type(s)
$ sho sym %
  S = ""
  T = "STRING"
$ tcpip show version

  HP TCP/IP Services for OpenVMS Alpha Version V5.6 - ECO 5
  on an AlphaServer DS25 running OpenVMS V8.3   

 

The obvious difference is that I'm on Alpha and running 8.3 (nothing), but this code seems so fundamental to VMS you wouldn't think that it would change.

Trusted Contributor
John McL
Posts: 280
Registered: ‎02-24-2008
Message 4 of 8 (449 Views)

Re: F$TYPE of space is INTEGER

Sorry - my mistake.

 

A single space character does indeed return type "INTEGER", so does a string of two spaces and even a string of about 30 spaces.

 

Trusted Contributor
John McL
Posts: 280
Registered: ‎02-24-2008
Message 5 of 8 (448 Views)

Re: F$TYPE of space is INTEGER

Further, it looks like an issue with how VMS converts numeric strings into integers.

 

$ s = "0"
$ t = f$type(s)
$ sho sym t
  T = "INTEGER"
$ s = "A"
$ t = f$type(s)
$ sho sym t
  T = "STRING"

 

and here's why I think so ...


$ s = " "   ! space character
$ r = 4
$ x = r + s
$ sho sym x
  X = 4   Hex = 00000004  Octal = 00000000004

 

A string that's comprised of a space character, is treated as a 0 when processing integer arithmetic.

Trusted Contributor
abrsvc
Posts: 367
Registered: ‎06-08-2010
Message 6 of 8 (442 Views)

Re: F$TYPE of space is INTEGER

I haven't looked at the code, but I would expect that leading spaces are ignored in most cases when checking for integers and the result would end up being a zero length which is caught as the code already posted shows.

Dan
Honored Contributor
John Gillings
Posts: 2,995
Registered: ‎07-31-2003
Message 7 of 8 (414 Views)

Re: F$TYPE of space is INTEGER

Dan,

 

   I agree with Hein. It looks like a bug to me. However, I'd bet that if you report this, VMS engineering will say they can't fix it because folk may be depending on the bug behaviour. The curse of fanatical upwards bug-for-bug compatibility! I've had far more serious bug reports rejected on these grounds.

 

That said, in this case I think I'd reluctantly agree with them. This is very basic stuff, and the behaviour must have been there a very long time. There is a rather unconvincing argument that it could be considered kind of, sort of correct (but that would apply equally to the null string).

 

re: John McL> A string that's comprised of a space character, is treated as a 0 when processing integer arithmetic.

 

Well, all strings have a numeric value, it's just not always obvious what it will be. Most are zero, but not always. For example, here's a good DCL trivia question. How come some of these results are 5?

 

$ r=4
$ s="A String"
$ x=r+s
$   show sym x
  X = 4   Hex = 00000004  Octal = 00000000004
$ s="This String"
$ x=r+s
$ show sym x
  X = 5   Hex = 00000005  Octal = 00000000005
$ s="Yellow string"
$ x=r+s
$  show sym x
  X = 5   Hex = 00000005  Octal = 00000000005
$ s="New string"
$ x=r+s
$ show sym x
  X = 4   Hex = 00000004  Octal = 00000000004
$ s="Forgotten string"
$ x=r+s
$ show sym x
  X = 4   Hex = 00000004  Octal = 00000000004

 

A crucible of informative mistakes
Occasional Advisor
Lester_Dreckow
Posts: 9
Registered: ‎08-31-2011
Message 8 of 8 (392 Views)

Re: F$TYPE of space is INTEGER

> DCL trivia question

 

Good one John :-)

 

Cheers,

Lester

 

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.