Operating System - OpenVMS
1752717 Members
5577 Online
108789 Solutions
New Discussion

F$TYPE of space is INTEGER

 
Lester_Dreckow
Occasional Advisor

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

7 REPLIES 7
Hein van den Heuvel
Honored Contributor

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

 

 

John McL
Trusted Contributor

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.

John McL
Trusted Contributor

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.

 

John McL
Trusted Contributor

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.

abrsvc
Respected Contributor

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
John Gillings
Honored Contributor

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
Lester_Dreckow
Occasional Advisor

Re: F$TYPE of space is INTEGER

> DCL trivia question

 

Good one John :-)

 

Cheers,

Lester