SHARED statement
#1
I had a tutorial user contact me about using the SHARED statement. He was trying to share variables in a subroutine like this:

SHARED a, b, c AS INTEGER

According to the Wiki this is not an alternate method of using SHARED, however, the IDE accepts this form and there is no run-time error either.

Code: (Select All)
DIM AS INTEGER a, b, c

a = 10
b = 20
c = 30

Mysub


SUB Mysub ()

    '---------------
    ' ** Method 1 ** ------------> ** THIS WORKS **
    '---------------

    'SHARED AS INTEGER a, b, c ' all SHARED on a single line

    '---------------
    ' ** Method 2 ** ------------> ** THIS WORKS **
    '---------------

    'SHARED a AS INTEGER ' all SHARED on a separate line
    'SHARED b AS INTEGER
    'SHARED c AS INTEGER

    '---------------
    ' ** Method 3 ** ------------> ** THIS WORKS **
    '---------------
    'SHARED AS INTEGER a, b ' two different SHARED alternatives
    'SHARED c AS INTEGER

    '---------------
    ' ** Method 4 ** ------------> ** THIS DOES -NOT- WORK **
    '---------------

    'SHARED a, b, c AS INTEGER ' only the value of 'c' is passed, 'a' and 'b' are zero.

    '-----------------------------------------------------------------------------------
    ' Method 4 is not a valid alternative to SHARED listed in the Wiki and should
    ' therefore not work. However, I would think an error would be generated in the IDE
    ' or at least at run-time when SHARED is attempted to be used in this manner?
    '-----------------------------------------------------------------------------------

    PRINT a, b, c

END SUB

Shouldn't method 4 above get flagged somehow as being incorrect?
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply


Messages In This Thread
SHARED statement - by TerryRitchie - 03-14-2023, 07:16 PM
RE: SHARED statement - by bplus - 03-14-2023, 08:01 PM
RE: SHARED statement - by RhoSigma - 03-14-2023, 10:38 PM
RE: SHARED statement - by Kernelpanic - 03-14-2023, 11:33 PM
RE: SHARED statement - by SMcNeill - 03-15-2023, 01:43 AM
RE: SHARED statement - by TerryRitchie - 03-15-2023, 03:18 AM
RE: SHARED statement - by mnrvovrfc - 03-15-2023, 12:23 PM
RE: SHARED statement - by SMcNeill - 03-15-2023, 02:07 PM
RE: SHARED statement - by TempodiBasic - 03-19-2023, 11:51 PM



Users browsing this thread: 3 Guest(s)