Author Topic: Small syntax bug  (Read 2498 times)

0 Members and 1 Guest are viewing this topic.

Offline Ed Davis

  • Newbie
  • Posts: 40
    • View Profile
Small syntax bug
« on: January 28, 2021, 12:54:13 pm »
This code is intended to be used as a function, but I mistakenly used "exit sub", and "end sub" - and the QB64 compiler didn't catch it.
It compiles and runs, and even seems to work, and passes my unit tests (this function is from a much larger program).

Code: QB64: [Select]
  1. DIM SHARED pgm(1000) AS STRING
  2. ' finds target, using current sym
  3. FUNCTION get_target&
  4.     IF symtype = tynum THEN
  5.         get_target = expression#
  6.     ELSE
  7.         DIM i AS INTEGER, lbl AS STRING
  8.         lbl = sym
  9.         IF RIGHT$(lbl, 1) <> ":" THEN lbl = lbl + ":"
  10.         FOR i = 1 TO pgmsize
  11.             IF LCASE$(MID$(LTRIM$(pgm(i)), 1, LEN(lbl))) = lbl THEN
  12.                 get_target& = i
  13.                 EXIT SUB ' should be exit function
  14.             END IF
  15.         NEXT
  16.         PRINT at_line$; "Target of goto not found:"; sym: errors = true
  17.         get_target& = 0
  18.     END IF
  19. END SUB ' should be end function
  20.  

FellippeHeitor

  • Guest
Re: Small syntax bug
« Reply #1 on: January 28, 2021, 12:55:46 pm »
Yeah, QB64 intentionally ignores the difference between END FUNCTION/END SUB, EXIT FUNCTION/EXIT SUB. Both have the same purpose and it's one less error.

Notice that QB4.5 would change it for you - we just let you be.

Also, internally both translate to a mere "}", that's why it doesn't really matter.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Small syntax bug
« Reply #2 on: January 28, 2021, 12:59:13 pm »
I don't want to make you guys extra work, but why not change it to...

EXIT WHATEVER

Okay, I was kidding. I do want to make you guys extra work!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/