Uninitialised variables

Previous topic - Next topic

AndyH

Is there an option to force GLBasic to throw an error or warning if you reference and uninitialised variable in the code?  It's one of those things that can lead to mind-boggling annoying errors in your own code when you misspell one of your own variables!

Blitzmax has strict and superstrict to deal with this.

kin

aint the message section on the bottom show enough info?
i get to see unassigned variable etc.. for example after pressing "start game" button.

AndyH

I hadn't noticed them there.  Guess that this is a place to keep an eye on, would be handy if you could choose to have the editor to capture these warnings and throw you back to the code editor with it (as SuperStrict or Option Explicit would do).

Schranz0r

Use the Debug Modus, so you can see all non-declare vars in you're code!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

AndyH

How do you do that?

Schranz0r



Press this button, and run the game/programm!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

AndyH

I had a play around with the debugger (very good it is too) but I don't think it shows what I'm really looking for.    I see my globals and locals but it looks like these come from the compiler and show as being initialised with a value of 0 which I'd expect as they are usable by my program.  Could you let me know if I've misunderstood what your pointing to.

Here's an example of the output window:

"Test1.gbas"(43) warning : probably unassigned variable : y
"LoadSpriteSet.gbas"(13) warning : implicitly created GLOBAL  : tt
"LoadSpriteSet.gbas"(28) warning : implicitly created GLOBAL  : y

These are good messages, and somewhere I can at least look to.  Would be great if the editor can trap these however, because unassigned and implicitly created variables are a common source of problems.  Not so much a problem for small projects, but they can be a right pain on larger and more complex projects.  An Option Explicit (as in VB) or SuperStrict type option would be a nice feature to have in GLBasic if the user chooses to use it.  Can save you time in the long run :)

Kitty Hello

I always compile and remove these whenever I see one. Thus, I go superscrict. Just double click on the warning to get there.