BasicX Port - Module Level Variables

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
everest
Posts: 96
Joined: 31 May 2010, 9:01 AM

BasicX Port - Module Level Variables

Post by everest »

Hey Don,

I've found a BasicX port of the AtomPro code I've been trying to port to Zbasic. . .and it would seem that porting from BasicX is MUCH easier! So I'm porting the port, so to speak. Anyways, it's been pretty easy with one exception.

I'm getting a lot of warnings from the Zbasic IDE:

"BasicX Code.bas:752: Warning(5): parameter "GaitLegNr" hides module-level variable"

I'm not entirely sure what that means, but suspect it's because there is a global variable name that is also used while defining the subroutine, making the two collide somehow?

Do I need to assure strict segregation between the two? I've attached the code in case it helps illustrate the issue. The errors are quite obvious upon compilation!

-Jeff
Attachments
BasicX - Zbasic Port.bas
(40.45 KiB) Downloaded 1055 times
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: BasicX Port - Module Level Variables

Post by dkinzer »

everest wrote:I'm not entirely sure what that means, but suspect it's because there is a global variable name that is also used while defining the subroutine, making the two collide somehow?
The warning is just to inform you that inside that procedure you won't be able to access the module level variable because any reference to GaitLegNr will refer to the parameter. The same situation would occur if you were to define a variable inside the procedure with the same name as the module level variable.

You can either ignore this warning or fix it in one of two ways. The simplest way is to add a pragma to suppress the warning. Near the top of the module, add this line:

Code: Select all

#pragma warning(5:Off)
The value 5 is the warning number that is displayed in the warning message. This form and placement turns off the warning for the entire module; other forms and placements can be used to be more selective. See the ZBasic Language Reference Manual section entitled Controlling Warnings for more information.

The second way to fix the problem is to rename either the module-level variable or the parameter/local variable. This is more work but it is a better long-term solution. To rename the parameter/local variable, you can cut the procedure to the clipboard, paste it in an empty file, do a search-and-replace on the name and then copy/paste it back to the original file. This technique makes it easier to avoid unintended changes. Another alternative is to select the entire procedure and then use the "Replace in Selection" button on the "Replace..." dialog in the IDE.
- Don Kinzer
Post Reply