Meta Commands - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: Meta Commands (/showthread.php?tid=1128) Pages:
1
2
|
Meta Commands - NasaCow - 11-16-2022 Can meta commands such as option base 0 or 1 or option _explicit be set to only affect the main program and not the included libraries? If not, be a cool addition to the IDE instead of being forced to be using the defaults. RE: Meta Commands - mnrvovrfc - 11-16-2022 Welcome to the forums! Technically "OPTION" is not a metacommand. QuickBASIC only supported "BASE" second keyword which was only to change the first subscript to dimension an array, either zero or 1, when the programmer doesn't use a statement like "DIM A(1 TO 10) AS INTEGER". The "OPTION _EXPLICIT" is a QB64-only thing; note that other BASIC's don't carry the underscore in the same statement, although there is "$NOPREFIX" metacommand to suppress the leading underscore from QB64-only keywords. "OPTION" is recommended used near the top of the program before any executable statements and preferably before any variable is declared or created. A metacommand, which is not compatible with Q(uick)BASIC must begin with "$" such as "$NOPREFIX", "$CONSOLE:ONLY" or "$CHECKING:OFF". The ones compatible with Q(uick)BASIC must begin with "REM" or apostrophe, then "$" then "keyword" and then it depends such as "'$INCLUDE: 'file.bi'" or "'$STATIC". Those older metacommands must be treated like remarks, not like the QB64-only ones or the compiler throws an error. https://qb64phoenix.com/qb64wiki/index.php/Metacommand BTW do not use double quotation marks in any of those statements for source code, it's a tendency of mine. RE: Meta Commands - bplus - 11-16-2022 (11-16-2022, 03:41 AM)NasaCow Wrote: Can meta commands such as option base 0 or 1 or option _explicit be set to only affect the main program and not the included libraries? If not, be a cool addition to the IDE instead of being forced to be using the defaults. I would say no. Steve has already lamented how Option _Explicit even effects code in libraries back at old forum. What defaults are you being forced to use? Default usually means something will be used if you haven't declared a preference. Option base 1 or 0 are old compatibility Options, you can start and stop an array anywhere eg, Dim arr(-100 to 100) RE: Meta Commands - NasaCow - 11-16-2022 Perhaps I have been calling them the wrong thing for a very long time. What has happened is when I included Ritchie's QB64 Menu Library and tried to switch to OPTION BASE 1, it throws an array out of bounds inside the library when it is ran but it doesn't when the base is set to zero. So my question is with these options or commands (whatever they are called collectively), is there a way to use them only in my main .BAS file and not "bleed over" to the .BI files. Sorry if I was imprecise with my language, a great sin for a programmer RE: Meta Commands - NasaCow - 11-16-2022 (11-16-2022, 05:13 AM)bplus Wrote:(11-16-2022, 03:41 AM)NasaCow Wrote: Can meta commands such as option base 0 or 1 or option _explicit be set to only affect the main program and not the included libraries? If not, be a cool addition to the IDE instead of being forced to be using the defaults. I guess I am the odd one that really likes to use $NOPREFIX command and I also really, really like OPTION _EXPLICIT. I know it is just preference and working around it, just miss it for this program I am writing Good point on array defining, I shouldn't be lazy to use the style I want! RE: Meta Commands - SMcNeill - 11-16-2022 (11-16-2022, 11:44 AM)NasaCow Wrote: Perhaps I have been calling them the wrong thing for a very long time. Afraid not, and if you think about it for a moment, you'll see why. Let's say you write a very simple program: Code: (Select All) OPTION BASE 1 Simple enough -- you wrote a SUB which counts the lines in an text file and saves them to a string array. Written as is, it works flawlessly. Now, imagine a few months later, you've assured yourself that this is THE bestest best ever line counting, array storing routine, so you decide to take it out of your program and save it as "CountLines.BM"... You share it with all your friends... ...and suddenly it's not working as advertised!! It went from a routine inside the main BAS file to simply being one inside a BM file, and now it's not working because that OPTION BASE 1, which you *always* tend to use as default in your programs, doesn't work with the $INCLUDES. Coding for one's self, a lot of these ideas seem like great ideas. Once one starts coding and releasing that code to the public however, it becomes the wild, wild west out there. Yoiu have to try to imagine not just how people like you would use the commands, but how it'd affect people who's coding style is almost completely foreign to you, and yet they're using the language you've produced. If "OPTION BASE 1" were included in a *.BI file, how far should that influence reach? Only to that BI file? Only to the file and a similarly named *.BM file? But what if it passes shared variables back to the main program -- would those be BASE 1 or BASE 0? IF the main module has an array called FOO(), and $DYNAMIC is in use, then FOO() is resizable. Now, if there's a REDIM foo() inside an $INCLUDE file, is that foo() resizeable? Is it even the same array, or does it create a new STATIC array now? How's the change to localized Metacommands affected it? In the wild, wild west of open-source coding, such a command would likely break zillions of old programs. People would start shouting, "AHHH!! MY OLD SHIT DOESN"T WORK ANY MORE!! FIX IT!!!" v1.5 had a "fix" to recursive functions in it, that changed how they worked for people -- and that STILL gets folks posting about it on a regular basis asking about, "Why my shit no work no more?" That's with just a change to ONE single keyword... I can't even begin to imagine how many people would faint, explode, and murder someone, if the behavior of all the MetaCommands was suddenly changed on them.... RE: Meta Commands - TerryRitchie - 11-16-2022 Perhaps a command can be added for library writers to test for this? CheckBase% = _OPTIONBASE Returns 1 if OPTION BASE 1 Returns 0 if OPTION BASE 0 Returns -1 if OPTION BASE was not set I was just playing around with OPTION BASE and arrays and I think I may have found a solution for library writers. If I do this: OPTION BASE 1 DIM a(100) a(0) = 10 I get an error. However, if I do this: OPTION BASE 1 DIM a(-1 to 100) a(0) = 10 all is well. As long as the first number in an array is a negative value it seems to allow the use of index 0 and 1 no matter what OPTION BASE is set to. So for arrays in libraries always start them at -1 and any setting by the programmer using OPTION BASE seems to be ignored. Is this normal behavior or a loophole that I've found? RE: Meta Commands - SMcNeill - 11-16-2022 For Library writers, I'd suggest always dimming both upper and lower bounds. DIM a(0 to 100) or, if you like OPTION BASE 1: DIM a(1 to 100) You never know what someone will have in their program where they include your library file, so it's best to be as self-contained as possible. In both cases above, it doesn't matter what the option base is, as you've explicitly defined what the upper and lower limits of your arrays are going to be. RE: Meta Commands - RhoSigma - 11-16-2022 Here's the transscript from the conclusion of a discussion we had with Steve, Terry and others a couple years ago on the old forum regarding the requirements for proper "Library authoring": Quote:Steve: I used this to condense it into some simple rules I follow in all my libraries (see links in my signature) to make them as compatible as possible. These rules are as follows (note the numbers in () which coresspond to the sections in the quote above): Quote:- Make a section in the beginning of each SUB/FUNC where you DIM all variables (OPTION _EXPLICIT requirements), even if you usually code without it. RE: Meta Commands - bplus - 11-16-2022 That looks very interesting thank RhoSigma! |