Question about a question mark??

General FreeBASIC programming questions.
Post Reply
davidj
Posts: 13
Joined: Jul 22, 2016 18:16

Question about a question mark??

Post by davidj »

Hi all, I've been working on a project in fbc and its been working out really well, I'm loving it so far. It helps that the language flows like water after years and years of hacking on BASIC in times past, but I've stumbled across something that has me absolutely stumped. I'm working with a PostgreSQL database, and working from the example I've stumbled upon this bit of code.

Code: Select all

	
res = PQexec(conn, "SELECT * FROM pg_database")
? PQresultStatus(res) '<-This, right here!  What the heck is this!
	if (PQresultStatus(res) <> PGRES_TUPLES_OK) then
		Print "Command failed: "; *PQerrorMessage(conn)
		PQclear(res)
		exit_nicely(conn)
	end if
My question is simply this: what does the question mark before the function call on line 2 do? I know this is probably super simple, but all of my searching (and believe me, it was a lot) has came up empty. Please help, thank you!
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Question about a question mark??

Post by dkl »

The ? is an old-school (QBASIC) alternative for Print - it can also be found on the keyword list.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Question about a question mark??

Post by Tourist Trap »

dkl wrote:The ? is an old-school (QBASIC) alternative for Print - it can also be found on the keyword list.
It's a (pretty) residue from the time where every bit saved of source code would save storage (disk/memory). ? is my favourite (old time command), with Print@ ("print at"), with is just the equivalent of Locate, if I remember well (should be for instance in use in c64 basic I guess).

[edit] not sure exactly how memory was affected with the keywords and useless spaces. See rightful marcov remark below.
Last edited by Tourist Trap on Jul 25, 2016 12:08, edited 1 time in total.
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: Question about a question mark??

Post by jevans4949 »

It was a very useful abbreviation when debugging your early attempts a programming in Basic.

Back when I started in the late 1960's, we used hard-copy teletypes, and Print really did mean print!
davidj
Posts: 13
Joined: Jul 22, 2016 18:16

Re: Question about a question mark??

Post by davidj »

I guess I could have done a bit more due diligence and opened up a debugger or something, but then I wouldn't have got the cool history lesson. Thanks a lot everyone, I really appreciate your help :)
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Question about a question mark??

Post by marcov »

Tourist Trap wrote: It's a (pretty) residue from the time where every bit saved of source code would save storage (disk/memory).
No, I think it is just typing. Most old interpreted BASICs stored their sources tokenized, not as textfiles (which is more a PC concept). Including e.g. C=64. So a ? and print would be stored as the same token, both in memory and on disk.

Interpretation speed also benefited of course.
? is my favourite (old time command), with Print@ ("print at"), with is just the equivalent of Locate, if I remember well (should be for instance in use in c64 basic I guess).
Well, C=64 basic is also a Microsoft Basic (V2), though still spelled as "Micro Soft" back then.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Question about a question mark??

Post by Tourist Trap »

marcov wrote: So a ? and print would be stored as the same token, both in memory and on disk.
On disk, if your source stores one char, rather than 5, it can make you save some space.

But maybe all things were tokenized as well as spaces removed before any storage operation. This would be possible to test this by saving a code with an excess of spaces and reload it, to watch if useless spaces are still here. Or simply use a hex editor. Same can be done with memory.

[EDIT] Not sure if CCS64 emulator takes care to save as PRG as they would be in real C64, but if it does so, we see from the test below that the keyword is well tokenized whereas spaces are not (removed/reduced):
Image

Once restored, the program is rendered as follows:
Image
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Question about a question mark??

Post by grindstone »

The space wasn't used as delimiter in C64 code. Instead, every character sequence matching a keyword was tokenized. So you could write code like

Code: Select all

FORX%=1TO10:?X%:NEXT
(without any space) and it would work. On the other hand you were not allowed to use variable names containing any keyword sequence like "MOTOR", because of the keyword "TO" (Aside from the fact that variable names were distinguished only by the first two characters).
Post Reply