BMXNG compiling problem with externed types
BlitzMax Forums/BlitzMax NG/BMXNG compiling problem with externed types
| ||
This example code fails to build:SuperStrict Extern "c" Type MyType EndType Type MyTypeExt Extends MyType EndType EndExtern Function TestFunc(objext:MyTypeExt) Local obj:MyType = objext EndFunction Here is the output: Building buildtest [ 99%] Processing:buildtest.bmx [ 99%] Compiling:buildtest.bmx.gui.release.win32.x86.c C:/Leadwerks/Engine/Source/.bmx/buildtest.bmx.gui.release.win32.x86.c: In function '_buildtest_TestFunc': C:/Leadwerks/Engine/Source/.bmx/buildtest.bmx.gui.release.win32.x86.c:3:88: error: 'MyType' undeclared (first use in this function) struct MyType_ext* volatile bbt_obj=((struct MyType_ext*)bbObjectDowncast(bbt_objext,&MyType)); ^ C:/Leadwerks/Engine/Source/.bmx/buildtest.bmx.gui.release.win32.x86.c:3:88: note: each undeclared identifier is reported only once for each function it appears in Build Error: failed to compile (1) C:/Leadwerks/Engine/Source/.bmx/buildtest.bmx.gui.release.win32.x86.c Process complete Any idea what's going on here? It seems to be caused by the downcasting. Thanks in advance. |
| ||
Is this for NG? works on vanilla btw.Building untitled1 Compiling:untitled1.bmx flat assembler version 1.69.14 (1407625 kilobytes memory) 3 passes, 2181 bytes. Linking:untitled1.exe Process complete |
| ||
Yes, I totally forgot to mention that. :D |
| ||
Aha ok JoshK. Not sure but I think I found a related thread on that here and this is from Brucey http://www.blitzbasic.com/Community/post.php?topic=106260&post=1306276 Something about extern and structs vs types I would assume since it works in vanilla. |
| ||
I don't see what that has to do with this problem. |
| ||
Ok just trying something here. btw, I got a different error with my NG setup in case you're interested..Building untitled1 [ 97%] Processing:untitled1.bmx [ 98%] Compiling:untitled1.bmx.gui.release.win32.x86.c C:/BMXNG/tmp/.bmx/untitled1.bmx.gui.release.win32.x86.c: In function '_m_untitled1_TestFunc': C:/BMXNG/tmp/.bmx/untitled1.bmx.gui.release.win32.x86.c:3:25: error: expected expression before ';' token struct MyType* bbt_obj=; ^ Build Error: failed to compile C:/BMXNG/tmp/.bmx/untitled1.bmx.gui.release.win32.x86.c Process complete |
| ||
Yeah, I get that when I updated to the latest. The offending line in the C source looks like this:bbt_obj=; So it looks like it's not handling the variable assignment / downcasting. The generated code should be something like this: bbt_obj=(MyTypeExt*)bbt_objext; |
| ||
I'm not sure since I'm not that advanced and active with NG anymore, unlike before. I'm sure Derron and Brucey could help you this, but there's already an issue of this months back and I'm not sure if this has been resolved (it's already a Closed issue). It's a long discussion so maybe you need to take a look at this and maybe get some info. Are extern types working just yet? https://github.com/bmx-ng/bcc/issues/145 |
| ||
Reported here: https://github.com/bmx-ng/bcc/issues/227 |
| ||
This surely looks like a compiler bug. With the bug aside... Be aware that extern Types and Interfaces can be used to work with c++ as long as the object/interface hierarchy is the same layout in NG and c++, they have to mirror each other or you'll get undefined behaviour. @RustyKristi Your link is the initial conversation/work of Brucey and I implementing external types and interfaces for NG :O) |
| ||
Fortunately I never use fields or methods in C++ types from BlitzMax. I just need the hierarchy of classes to work so the functions will accept the right type of object. |
| ||
@col Ah nice :) |
| ||
I am not the one writing that C-stuff, so chances are bigger (with me: nonexistent) that brucey or col or ... fix that issue. @ JoshK Your lines read as if it worked some revisions before ("[...] when I updated to the latest [...]"). If you find the time: narrow it down until which revision it works (speed up by skipping revisions and narrowing down at the end). Maybe that eases the bugfix. bye Ron |
| ||
As it's a compiler issue I would think Brucey will be the one to fix it. Fortunately I never use fields or methods in C++ types from BlitzMax. I just need the hierarchy of classes to work so the functions will accept the right type of object. Just a heads up that even if you don't use the methods you'll still need the exact same class<-->type method hierarchy layout for MaxNG and c++, this makes sure the binary layout mirrors each other for your 'cross-language' code to work properly. |
| ||
You probably want to be doing this instead:SuperStrict Framework brl.standardio Extern "c" Interface MyType End Interface Interface MyTypeExt Extends MyType End Interface EndExtern Function TestFunc(objext:MyTypeExt) Local obj:MyType = objext EndFunction where your "objext" instance is created externally (like from some C/C++ library). As col says, if your methods are lined up correctly, you should be able to call the (external) methods (from BlitzMax) without too many problems. |
| ||
Your code using "Interface" does work correctly. What is the difference between an "Interface" and a "Type"? How often does NG deviate from stock BMX? The reason I am concerned is because I want to be able to retain the ability to flip back and forth between compilers, for improved bug testing and to make sure things are working as expected. If this all works, I will have Leadwerks Game Launcher using it by December. Overall, BMXNG is looking really good. |
| ||
What is the difference between an "Interface" and a "Type"? An Interface in MaxNG relates to an interface for c++ - ie that would be a pure abstract class with no constructor/destructor. A Type would relate to a regular c++ class - ie one with constructors and destructor. Both require all functions to be virtual. |