BCX Basic Forum

BCX Basic => Bug Reports => Topic started by: Robert on June 15, 2020, 09:55:11 PM

Title: ENUM SUB main()
Post by: Robert on June 15, 2020, 09:55:11 PM
ENUM is misplaced after main in the C translation

Code: [Select]

 $NOMAIN

 ENUM Mon=1, Tue, Wed, Thu, Fri, Sat, Sun

 SUB main()
  PRINT Wed
  KEYPRESS
 END SUB


translates, in part, to

Code: [Select]

int main (void)
{
  printf("% d\n",(int)Wed);
  keypress();
  return 0;
}


enum Mon{Mon  = 1, Tue, Wed, Thu, Fri, Sat, Sun};



ALSO NOTICE extra space added

Code: [Select]
Mon=1
translates to

Code: [Select]
Mon  = 1
Title: Re: ENUM SUB main()
Post by: MrBcx on June 15, 2020, 10:37:18 PM
Here's a working alternative, if you want it.

Code: [Select]

$NOMAIN

ENUM
   Mon=1
   Tue
   Wed
   Thu
   Fri
   Sat
   Sun
END ENUM


SUB main()
   PRINT Wed
   KEYPRESS
END SUB

Title: Re: ENUM SUB main()
Post by: Robert on June 15, 2020, 10:54:48 PM
Here's a working alternative, if you want it.

Code: [Select]

$NOMAIN

ENUM
   Mon=1
   Tue
   Wed
   Thu
   Fri
   Sat
   Sun
END ENUM


SUB main()
   PRINT Wed
   KEYPRESS
END SUB


Thanks but in the circumstances it is of no help.

The code I posted is from the ENUM page of the BCX Help file where that code is offered as an alternative second method to the ENUM ... END ENUM block.

The Help file says

Quote
In a console application, if a global ENUM is needed, the above restriction regarding scope can be circumvented by using the ENUM ...END ENUM block syntax which is always GLOBAL in scope. A second method for global scope is to use the $NOMAIN directive and a SUB main() as in this example.

Well, it used to work but does not now so I will delete that section of the ENUM page.

Title: Re: ENUM SUB main()
Post by: MrBcx on June 15, 2020, 11:18:52 PM
The code preceding this is so confusing, I wonder if this ever gets called anymore.

Code: [Select]
'*************************************************************
'  We're dealing with a smaller, single line ENUM statement
 '*************************************************************

            Stk$[1] = "enum {"
            FOR j = 2 TO Ndx
               CONCAT (Stk$[1], Stk$[j])
            NEXT
            CONCAT (Stk$[1], "}")
            Ndx = 1

Title: Re: ENUM SUB main()
Post by: Robert on June 16, 2020, 12:49:08 AM
The code preceding this is so confusing, I wonder if this ever gets called anymore.

Code: [Select]
'*************************************************************
'  We're dealing with a smaller, single line ENUM statement
 '*************************************************************

            Stk$[1] = "enum {"
            FOR j = 2 TO Ndx
               CONCAT (Stk$[1], Stk$[j])
            NEXT
            CONCAT (Stk$[1], "}")
            Ndx = 1

The code preceding this is so confusing, I wonder if this ever gets called anymore.

Code: [Select]
'*************************************************************
'  We're dealing with a smaller, single line ENUM statement
 '*************************************************************

            Stk$[1] = "enum {"
            FOR j = 2 TO Ndx
               CONCAT (Stk$[1], Stk$[j])
            NEXT
            CONCAT (Stk$[1], "}")
            Ndx = 1


Yes, ENUM had all the bells and whistles.

Have a look at the examples on the help file ENUM page. The last example no longer works either and so I have deleted that as well.
Title: Re: ENUM SUB main()
Post by: MrBcx on June 16, 2020, 01:07:34 AM
The alternative I provided earlier yields an enum of global scope which was the point of the Help file example.

The results of the original and my revised version are the same ... the only difference is that my alternative
uses a multi-line ENUM block format.
Title: Re: ENUM SUB main()
Post by: Robert on June 16, 2020, 01:50:41 AM
The alternative I provided earlier yields an enum of global scope which was the point of the Help file example.

The results of the original and my revised version are the same ... the only difference is that my alternative
uses a multi-line ENUM block format.

I have used your example to replace the one that was removed and modified the descriptive text from this

Quote
In a console application, if a global ENUM is needed, the above restriction regarding scope can be circumvented by using the ENUM ...END ENUM block syntax which is always GLOBAL in scope. A second method for global scope is to use the $NOMAIN directive and a SUB main() as in this example.

to this

Quote
In a console application, if a global ENUM is needed, the above restriction regarding scope can be circumvented by using the ENUM ...END ENUM block syntax which is always GLOBAL in scope as in this example.

The order of the ENUM descriptions and examples has also been changed for clarity.
Title: Re: ENUM SUB main()
Post by: MrBcx on June 16, 2020, 09:29:46 AM
Code: [Select]

───────────────────████
───────────────────█████
───────────────────██████
───────────────────███████
──────────────────████████
──────────────────████████
─────────────────█████████
────────────────█████████
───────────────█████████
──────────────█████████
──────────────██████████████████
────────────█████████████████████
───────────███████████████████████
████████─██████████████████████████
████████─███████████████████████████
████████─████████████████████████████
████████─████████████████████████████
████████─████████████████████████████
████████─████████████████████████████
████████─███████████████████████████
████████─██████████████████████████
████████─█████████████████████████
████████─████████████████████████
████████─███████████████████████

Title: Re: ENUM SUB main()
Post by: MrBcx on June 16, 2020, 02:28:20 PM
The order of the ENUM descriptions and examples has also been changed for clarity.

One more tweak while you're in the ENUM neighborhood

ENUM statement


Purpose: ENUM defines a list of variables...

to

Purpose: ENUM defines a list of named constants...

Title: Re: ENUM SUB main()
Post by: Robert on June 16, 2020, 04:20:37 PM
Code: [Select]

───────────────────████
───────────────────█████
───────────────────██████
───────────────────███████
──────────────────████████
──────────────────████████
─────────────────█████████
────────────────█████████
───────────────█████████
──────────────█████████
──────────────██████████████████
────────────█████████████████████
───────────███████████████████████
████████─██████████████████████████
████████─███████████████████████████
████████─████████████████████████████
████████─████████████████████████████
████████─████████████████████████████
████████─████████████████████████████
████████─███████████████████████████
████████─██████████████████████████
████████─█████████████████████████
████████─████████████████████████
████████─███████████████████████


I put your message into OGLING Translator to be sure that I really understood what was what. The response was

Code: [Select]

_____&&&&&&&&
____ThumbsUp!&
___ThumbsUp!&&&
___ThumbsUp!&&&
___ThumbsUp!&&&
__ThumbsUp!&&&&
_ThumbsUp!&&&&
_ThumbsUp!&&&&
_ThumbsUp!&&&&&&&
ThumbsUp!ThumbsUp!&&
ThumbsUp!ThumbsUp!&&&&&
ThumbsUp!ThumbsUp!&&&&&&
_&&&&&&__ThumbsUp!&&&&&
___&&&&____ThumbsUp!&&
___&&&&_____ThumbsUp!&
___&&&&_____ThumbsUp!&
____&&&&____ThumbsUp!&
_____&&&____ThumbsUp!
______&&&__ThumbsUp!&
_______ThumbsUp!&&&&&
________ThumbsUp!&&s&&
_______ThumbsUp!ThumbsUp!
_______ThumbsUp!ThumbsUp!&&&
_______ThumbsUp!ThumbsUp!&&&&&&&
_______ThumbsUp!ThumbsUp!ThumbsUp!
________ThumbsUp!&____ThumbsUp!&&s&
_________&&&&&&&&_______ThumbsUp!&&
_________&&&&&&&&_____ThumbsUp!&&
_________&&&&&&&____ThumbsUp!&
_________&&&&&&&_ThumbsUp!&
________ThumbsUp!&&&&&&
________ThumbsUp!&&&
________ThumbsUp!&
_______&&&&&&&&
_______&&&&&&
______&&&&&&
______&&&&&&
______&&&&&&
______&&&&&
______&&&&&
_______&&&&
_______&&&&
_______&&&&
______&&&&&
______&&&&&
_______&&&&
_______ &&&&&
________&&&&