print# without open file

Forum for discussion about the documentation project.
Post Reply
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

print# without open file

Post by sancho3 »

Print# does not produce an error message if there is no open file. If the file number is invalid it prints to the console.

Code: Select all

print#7, "test"   ' no error and prints to console
This is probably not a but I think it deserves mentioning in the documentation.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: print# without open file

Post by fxm »

With Win7, nothing is printed on the console.
SARG
Posts: 1764
Joined: May 27, 2005 7:15
Location: FRANCE

Re: print# without open file

Post by SARG »

Code: Select all

print#7, "test" 
prints 7 and test

but with a space between print and #7

Code: Select all

print #7, "test" 
prints nothing

W10 here, I guess it doesn't matter.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: print# without open file

Post by fxm »

With fbc 1.06, I get the following error without space between 't' and '#':
error 148: Suffixes are only valid in -lang fb or deprecated or fblite in 'print#7, "test"'
Because:
fbc rev 1.06:
[fixed]
- #832: Fix bug allowing QB style suffixes on all keywords, regardless of -lang

With a previous fbc version, I suppose that without space, "#7" is ignored when -lang fb.
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: print# without open file

Post by sancho3 »

I see the documentation syntax has a space between print and # as do the examples.
Its my habit to not have a space between the print and #. That is my mistake and I won't do that anymore.

On linux using fbc 1.05 and with a space properly inserted between the print and #, I also get no output.

So regarding the origninal issue it seems there actually should be an error message saying something like "Error: invalid file number with print # ".
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: print# without open file

Post by fxm »

Code: Select all

Print "FreeBASIC"
Print Err
Print

Print #7, "FreeBASIC"
Print Err

Sleep

Code: Select all

FreeBASIC
 0

 1
At the compilation level of the module, we can not know that '#7' is not a valid file number.
This verification can only be done at runtime.
The runtime error can be caught by testing the 'Err' value just after the 'Print #' statement.
Post Reply