Is there any difference between dim shared and common shared?

New to FreeBASIC? Post your questions here.
Post Reply
htm_hx
Posts: 17
Joined: May 24, 2017 19:42

Is there any difference between dim shared and common shared?

Post by htm_hx »

Is there any difference between dim shared and common shared?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Is there any difference between dim shared and common shared?

Post by fxm »

- 'Dim Shared' declares (and defines) a global variable inside one code module (it can be used inside the Subs and Functions of the module where it is declared, as well as at main level of this module).
- 'Common Shared' declares (and defines) also a global variable as above, and in addition it can be shared between several code modules (a 'Common Shared' declaration with same variable name must be put in each module where sharing is requested).
- If 'Dim Shared' with the same variable name is declared in several code modules, each global variable remains independent in its code module.

For more information about the visibility of a variable, see at Introduction to Variable Scope.
htm_hx
Posts: 17
Joined: May 24, 2017 19:42

Re: Is there any difference between dim shared and common shared?

Post by htm_hx »

Thank you very much for your detailed explanation ~ let me know more about FB
Post Reply