March 28, 2024, 11:43:53 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


ONEXIT Command

Started by Logman, August 20, 2015, 06:00:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Logman

August 20, 2015, 06:00:17 AM Last Edit: August 20, 2015, 06:03:54 AM by Logman
PROBLEM - The ONEXIT command gives spurious warnings and does not always work correctly.

Click on the HELP menu and then select IWBasic User's Guide.

In the User's Guide go to SEARCH and enter "ONEXIT".

Find "ONEXIT" in the Select Topic window. It will bring up the ONEXIT Topic as follows:

=============================================================
ONEXIT

Syntax
ONEXIT(fn as UINT,pData as POINTER)

Description
Adds a subroutine to the on-exit list.

Parameters
fn - Address of subroutine.
pData - Pointer to user data or NULL

Return value
None

Remarks
The functions in the on-exit list are called in LIFO (Last In First Out) order when your program exits. The DECLARE for an on-exit function must include one parameter of type POINTER. A subroutine can be added more than once.

Example usage

OPENCONSOLE                   ' Added by me to make program work
ONEXIT(&myfunc1,NULL)
ONEXIT(&myfunc2,NULL)
ONEXIT(&myfunc1,"hello")
DO: UNTIL INKEY$ <> ""    ' Added by me to make program work
CLOSECONSOLE                 ' Added by me to make program work
END

SUB myfunc1(pData as POINTER)
 IF pData = NULL
   MESSAGEBOX 0,"myfunc1","TEST"
 ELSE
   MESSAGEBOX 0,"myfunc1",#<STRING>pData
 ENDIF
 RETURN
ENDSUB

SUB myfunc2(pData as POINTER)
 MESSAGEBOX 0,"myfunc2","TEST"
 RETURN
ENDSUB


=============================================================

ISSUE - This particular code snippet works (sometimes), but renders the following spurious WARNINGS:

   File: ... IWBASIC1.iwb (5) WARNING: Argument1 (myfunc1) does not match the declaration of IWBONEXITCB
   Different return type: none, should be INT
   File: ... iwbstd.incc (327) WARNING: See previous declaration of IWBONEXITCB
   [SAME WARNING FOR THE OTHER TWO SUB CALLS]

If you open the IWBSTD.INCC file in the /bin folder, it lists the following for the ONEXIT command:

       declare IWBONEXITCB(POINTER pData),int
       $command ONEXIT(fn as IWBONEXITCB,pData as POINTER),INT

It appears that the IWBasic User's Guide states that the RETURN VALUE is NONE. However, in the iwbstd.incc file, it definitely indicates a RETURN VALUE of type INT.

FIX - The ONEXIT command needs to be cleaned up so it works properly and does not render spurious WARNINGS. Also, the IWBasic User's Guide needs to be edited to reflect the correct functionality of the ONEXIT command including the required return type.

In any case, I'd like to see an example that works correctly so I can feel confident in using this command in my code.

Thanks,
Logman

Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

LarryMc

In your Compiler Options menu option setup do you by any chance have Be Strict selected?

I've used the OnExit command like it is displayed and have never gotten the WARNINGS'

I've put it on mt todo list
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Logman

No, nothing checked off in the flags window of the compiler options menu.

Have you tried ONEXIT in version 3.03? I'll continue to investigate. I'd like to get it working properly.

Logman

Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

LarryMc

since it is just a warning it is not going to have any impact on the compile.

What I need to do is change the help file to reflect  the need for the return but that it is not normally used for anything; that it can be used for error code returns from a subroutine.

i.e. a help file change is all that is required to fix this issue.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Logman

Education is what you get when you read the fine print.<br />Experience is what you get when you don't!