An Unintended Consequence

Started by MrBcx, December 29, 2024, 04:33:26 PM

Previous topic - Next topic

jbk

that's very handy addition, if I remember right, freebasic also supports TYPE some_udt AS some_udt where some_udt is not defined anywhere else, I belive it translates to C void

MrBcx

#1
I was browsing some FreeBasic code and noticed this unfamiliar declaration (unfamiliar to me anyway):

TYPE Afx_IAxWinAmbientDispatch AS Afx_IAxWinAmbientDispatch_

which is copying a type definition ( Afx_IAxWinAmbientDispatch_ ) to a new name (Afx_IAxWinAmbientDispatch)  ... no trailing underscore

Here's a clearer way to think of it:  TYPE MyInteger AS INTEGER


All of which made me wonder whether BCX could correctly translate those kinds of statements.  So I threw
together a quick test and, lo and behold, it translates, compiles, and runs just fine.



TYPE A AS DOUBLE
TYPE B AS A
TYPE C AS B


DIM Foo AS C

Foo = ATN(1)*4
PRINT Foo   ' Default printing as single precision
PRINT Foo#  ' Force printing as double precision
PAUSE




BCX produced these relative parts



// *************************************************
//          User Defined Types And Unions
// *************************************************
typedef double A;
typedef A B;
typedef B C;

// *************************************************
//            User's Global Variables
// *************************************************

static C       Foo;



So there you have it!

If ever you find yourself converting FreeBasic code to BCX that uses those kinds of
declarations, it's good to know that BCX can handle them just fine.