Announcement

Collapse
No announcement yet.

END statement

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • END statement

    From the PBCC Help under END statement:
    "Normally, PowerBASIC programs are terminated when you exit the PBMAIN function. It should always be your goal to end programs in this fashion, so that the compiler and the operating system can do everything possible to leave things in an orderly state.
    "END is intended only for temporary use in converting DOS programs to Windows. You should convert it to the standard EXIT FUNCTION method as soon as possible. END must never be used in a program which uses COM access."



    OK, suppose the program doesn’t use COM access, whatever that is. What dire consequences await the hapless programmer who uses END, say in a subroutine, and leaves it there permanently? (Suppose the program keeps track of any system-wide changes it makes, such as changing the keyboard repeat key rate etc.-- what must etc. cover? -- and tidies up before executing END.)

    In practice it seems to work just fine.
    Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

  • #2
    > ...whatever that is...
    If you don't know what that is , how will you ever know whether your program uses it?

    > ... what dire consequences....
    I don't know, but do you have a good reason for ignoring this advice? Based on the warning, I'd guess that END is a call to TerminateProcess. I'll leave it to you to research why using that is not a Good Idea™

    > In practice it seems to work just fine.
    The first round of Russian Roulette frequently does too


    Comment


    • #3
      Stuart,

      I have a program that terminates using END and I’ve opened and closed it in all sorts of random conditions about a thousand times with no ill effects.

      TerminateProcess doesn’t look so bad.


      Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

      Comment


      • #4
        Originally posted by Mark Hunter View Post
        Stuart,

        I have a program that terminates using END and I’ve opened and closed it in all sorts of random conditions about a thousand times with no ill effects
        Because one program hasn't had a problem doesn't mean that it will not cause a problem in a different program.
        Like I said - "do you have a good reason for ignoring this advice?"

        Comment


        • #5
          The one program is very complex and well over 10,000 lines long. That the END statement works with it without any trouble says more than if the program were short and simple.

          In any case, my concern happens to be that one program. For those worried about my coding in general, it's the only PBCC program I've written that uses the END statement. My other programs are models of good form regarding termination.

          I use END in the one program mentioned above for two reasons, which may or may not be good reasons. First, I imagine that exiting in an unusual manner makes hacking the program more difficult. (Though my imagination may be perfervid.) Second, in this particular program, being able to exit within a subroutine rather than PBMain makes the coding a lot easier. Otherwise I'd have to use a terminate flag that gets handed back and back, eventually to the caller, and the program is so complicated it would take a lot of testing to implement the flag correctly.

          Besides, aren’t you curious about the Help instruction, paraphrasing: “Here is END but don’t use it for long or bad things will happen.”?

          Thanks Stuart for trying to help but can anyone answer the original question? To put it another way, what must the programmer do to ensure that the END statement works without a problem?
          Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

          Comment


          • #6
            Mark,

            Coding shortcuts will come back and bite you on the behind, exactly when you don't need it. Save yourself future hassles and terminate the app the right way.

            You can use "SendMessage hWin,%WM_SYSCOMMAND,%SC_CLOSE,NULL" in a UI app but you should properly return back to the entry point and use ExitProcess.
            hutch at movsd dot com
            The MASM Forum

            www.masm32.com

            Comment


            • #7
              What dire consequences await the hapless programmer who uses END, say in a subroutine,
              The answer is in your original question... "things the compiler does for you which you never see."

              One thing which can happen is, if you have a created a system object for which Windows - for its own purposes - has elected to create a temporary disk file, that file can live beyond program termination and consume disk space. Or, if you have something in a communications buffer when Windows closes the handle when the process ends, it may be lost.

              Lastly, you will never be able to "post failing code" here when you need help because each and every one of us will notice "END" and decide you are the type who should never see our daughters or grandaughters again. Ever.

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                I still think END works fine in the program I'm focused on. However, just for the challenge of it I removed the END at the end of the Tidy-Things-Up code, the only END in the program, and replaced it with exitflag = True, then I tracked all the different ways back to PBMain so it executes Exit Function when exitflag is set. You can try out the result here (download link at bottom of page).
                Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

                Comment


                • #9
                  Hi Mark,

                  Below is the basics of how simple it is to do it the right way and exit through the PBmain. I would not want to interfere with creative genius but the extra effort is 3 lines of code and it exits correctly.
                  Code:
                  ' --------------------------
                  
                   FUNCTION PBmain as LONG
                  
                      MyProc args
                  
                   End FUNCTION
                  
                  ' --------------------------
                  
                  FUNCTION MyProc
                  
                     ' your code
                  
                      FUNCTION = whatever
                  
                   End FUNCTION
                  
                  ' --------------------------
                  hutch at movsd dot com
                  The MASM Forum

                  www.masm32.com

                  Comment


                  • #10
                    Steve,

                    Maybe my last post wasn't clear. Program termination is now done the way the PBCC Help wants it done. The program's last gasp is Exit Function in Function PBMain.

                    But it took more than three lines to implement. It really had to be that way in this particular program. The user can initiate exit in a subroutine of a subroutine of a ... and you must keep track of the exitflag. Also there is Alt-F4 %WM_DESTROY to worry about.
                    Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

                    Comment


                    • #11
                      The compiler documentation as well as multiple experts in the PowerBASIC community have shared it is not wise. Apparently, however the code was written, it was not done with an early exit considered (which is part of programming 101 like error checking, input validation, etc.). In any event... you asked a question and a RESOUNDING answer was given. You obviously have a choice to make, do it the right way or do it the wrong way..

                      The thing that needs to be considered... who's PC is this impacting. If it's yours... do it your way, no one will care but you. If you are sharing / selling this app to others, it could cause negative issues on their machine, that is never good, regardless if your think it is or not. It comes down to being ethical with your clients... doing something wrong, purposefully, has the potential for gross negligence.
                      <b>George W. Bleck</b>
                      <img src='http://www.blecktech.com/myemail.gif'>

                      Comment


                      • #12
                        To all the goody-goodies, for the third time, the program I’m concerned with now terminates in the PBCC approved manner.
                        Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

                        Comment


                        • #13


                          I have never been classed as a goodie goodie before, thanks for the compliment. If you want to make a mess of it and write dodgy code, best of luck to you, you will need it.

                          Now just to make you wiser, the following simple code,
                          Code:
                          ' ------------------------------
                          
                          FUNCTION PBmain as LONG
                          
                              TestMe
                          
                          End FUNCTION
                          
                          ' ------------------------------
                          
                          FUNCTION TestMe() as DWORD
                          
                              StdOut "How D"
                          
                          End FUNCTION
                          
                          ' ------------------------------
                          Already hase ExitProcess without you having to add it yourself.
                          Code:
                          002017DD                    loc_002017DD:               ; Xref 002017CC 002017D5
                          002017DD 68FF000000             push    0FFh
                          002017E2 FF1500412000           call    dword ptr [ExitProcess]
                          002017E8 B000                   mov     al,0
                          002017EA CF                     iretd
                          hutch at movsd dot com
                          The MASM Forum

                          www.masm32.com

                          Comment


                          • #14
                            Steve,

                            Thanks for the disassembly. It's OK for Zale to use END but not us, LOL.

                            Naturally I don't want to make a mess of it. I just observe that in one particular practice END never caused any mess of it, as described in post #5 upthread. Proof of the pudding over years.

                            The goody-goody business was from my annoyance with GB for apparently not reading my posts with enough care to realize that I had taken your advice and gotten rid of END. It's not there anymore. I can hardly remember it ever being there.
                            Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

                            Comment


                            • #15

                              A REPLACEMENT FOR "END"
                              ==========================


                              I am not making this up.. I actually saw it done by two of my clients back in my contracting days.

                              When an error condition occurred for which the programmer wanted to immediately end the program, they would do (translated from COBOL) ....

                              Code:
                              ...
                                  GO TO  EXIT-PROGRAM.
                              
                              
                              EXIT-PROGRAM.
                                   DIVIDE  1  BY 0.
                              This creates a "divide by zero exception" on an IBM mainframe and ends the program immediately.




                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                Mark... I DID read your messages, and my post STILL applies. I said you had a choice. I didn't say which you did or didn't do, I said you had a choice and the choice was yours.

                                It's a shame you have to resort to name calling when you disagree with people. It's ESPECIALLY BAD when you call people names when they try to teach an ethical pathway. Based on your comments alone if I was client of yours I'd be very hesitant to trust your code as it seems clear you believe being ethical is for "goody goodies". Sure hope none read your public comments.

                                BTW Steve's post just showed a VERY SMALL ASM snippet --- with it you, of course, jump to the conclusion that it's "OK for Bob" --- all well written programs will have a termination sequence; Bob's code is no exception. What you failed to infer was that there was potential clean-up well before the EXIT PROCESS was called. You only saw what agreed with your opinion.
                                <b>George W. Bleck</b>
                                <img src='http://www.blecktech.com/myemail.gif'>

                                Comment


                                • #17
                                  Originally posted by George Bleck View Post
                                  You only saw what agreed with your opinion.
                                  So what's new?

                                  Comment


                                  • #18
                                    https://forum.powerbasic.com/forum/u...493#post808493
                                    Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

                                    Comment


                                    • #19
                                      Howdy, MCM!

                                      Funny story!

                                      With PowerBASIC there are actions (supplied by the compiler) which are taken when an app completes.

                                      I could imagine the case where a programmer would chose NOT to allow the shutdown actions to be taken and purposely creates a sudden end of the app (assuming it avoids the shutdown steps). It would require a lot of insight as to the shutdown actions that would be taken, more than we have documentation to support, so it's a very unlikely step to take.

                                      Even so, any chance a similar excuse might exist in COBOL? I've no insight into COBOL compilers and how they handle ending an application.

                                      Comment


                                      • #20
                                        I have never been classed as a goodie goodie before
                                        Nor are you likely to be in the future.
                                        Michael Mattias
                                        Tal Systems (retired)
                                        Port Washington WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X