print# without open file

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

print# without open file

Postby sancho3 » Dec 12, 2017 21:52

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
Posts: 7901
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: print# without open file

Postby fxm » Dec 12, 2017 22:56

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

Re: print# without open file

Postby SARG » Dec 12, 2017 23:24

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
Posts: 7901
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: print# without open file

Postby fxm » Dec 13, 2017 7:09

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: 233
Joined: Sep 30, 2017 3:22

Re: print# without open file

Postby sancho3 » Dec 13, 2017 23:35

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
Posts: 7901
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: print# without open file

Postby fxm » Dec 14, 2017 7:50

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.

Return to “Documentation”

Who is online

Users browsing this forum: No registered users and 1 guest