GLBasic forum

Feature request => IDE/Syntax => Topic started by: bigsofty on 2010-Aug-18

Title: Extended Types and Globals
Post by: bigsofty on 2010-Aug-18
Hi,

Just messing around with the extended types. A feature came to mind that I think would be beneficial for using extended types. Static global variables within extended types.

If an extended type has a variable, say X, then each instance of that extended type has a unique variable X.

If there was method of telling the compiler to create only one instance of a variable and share it between all the instances of the type it was defined in, then this would allow for the information to be shared within the type.

So...


Code (glbasic) Select
TYPE myType
   GLOBAL a
ENDTYPE

x1 as myType
x2 as myType

x2.a = 1
x1.a = 100

DEBUG "myType 'a' = " + x2


Result is "myType 'a' = 100"

Not a great example I know. :P

This is a similar method to BlitzMax I think.

This would remove the need for external global variables for types, making them more modular and  a bit easier to control IMHO.

Many thanks,


Ian
Title: Re: Extended Types and Globals
Post by: MrTAToad on 2010-Aug-19
I dont see it being useful myself. If you want to get rid of globals, you would put the variable in the type where it will be used or in a base type which will then be used by other types.
Title: Re: Extended Types and Globals
Post by: bigsofty on 2010-Aug-19
I don't want to define external globals that are only used within a certain type. This is quite a common syntax feature of many languages.

Its not essential though as it can easily be worked around if need be.

Cheers,


Ian