TYPE and CONST within SUB/FUNCTION
#5
(07-09-2023, 11:05 PM)Kernelpanic Wrote: Type . . . End Type definitions can not be declared in functions or procedures; the best place for them is at the beginning of a program - right after the constant declaration.
Actually clear, because what's the point of a type declaration in a procedure or function?

However, type definitions can be used as argument types of procedures and functions.

From MS-DOS QBasic - The Technical Reference; The Wait Group 1991/92
So perhaps the IDE accepting the creation of user defined TYPEs in SUBs and FUNCTONs is not desirable then. Should the IDE throw an error if TYPE ... END TYPE is used within a SUB or FUNCTION? I don't believe I've ever seen QBASIC/QuickBASIC 4.x code that used CONST or TYPE in a SUB or FUNCTION. KernelPanic's quote from the Qbasic tech reference seems to confirm at least that TYPE ... END TYPE was not allowed.

The weird behavior of CONST within in a SUB/FUNCTION got me thinking about all of this.

UPDATE: Ok, I fired up QuickBasic 4.5 and verified that you can indeed create TYPEs within SUBs and FUNCTIONs within the IDE and the IDE will even appear to use them as being global. However, when you try to compile it fails. TYPE ... END TYPE must be in the main program module.
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply


Messages In This Thread
RE: TYPE and CONST within SUB/FUNCTION - by TerryRitchie - 07-10-2023, 12:41 AM
RE: TYPE and CONST within SUB/FUNCTION - by bplus - 07-10-2023, 12:30 AM
RE: TYPE and CONST within SUB/FUNCTION - by bplus - 07-10-2023, 12:55 AM
RE: TYPE and CONST within SUB/FUNCTION - by bplus - 07-11-2023, 01:22 AM



Users browsing this thread: 2 Guest(s)