Replies: 2 comments
-
|
This is actually a general CRT question, it is the same with mixing GCC and MSVCRT and offen also when moving different versions of the MSVCRT.
Yes, moving them in one process is fine (and with libraries as QT also often the case), as long as you ensure that the free() is called from the same CRT that did the malloc(), the same it's true for functions using that, so a close() and open() needs to be done from the same CRT, too.
The memory (and, at least in all tests over did, also the FILE*) can then be used from another CRT.
It does come with culprits:
* you have to ensure to take care of the free/malloc issue, to support that libraries that return allocated memory often come with a function to free that or a function to pass a pointer to the allocation function which will be used for that allocation
* only the environment that was active at the process start is shared (setenv in one don't reach getenv in another CRT)
* it is a bad idea to mix CRT with buffered io, if you need that, then ensure that you flush() before "leaving your CRT" (actually this is always a good idea when you leave "your" functions and expect called functions to use io to the same targets - this is mostly about stdout/stderr)
These are my experiences on both Windows and GNU/Linux with several CRTs (with GnuCOBOL we write a COBOL RT which interacts a lot with several CRTs directly and via used libraries so that really _is_ experience).
|
Beta Was this translation helpful? Give feedback.
-
|
The FILE* from orange C isn't interchangeable with other compilers, unless you do something like link against MSVCRT.DLL in which case the results are probably compatible with most other windows compilers... in general I would be suspect of any program that used a structure that is not explicitly defined in the C language specification(or in a windows header) if i saw it passed between different CRTs, and even then there could be issues with packing and alignment of fields unless all the compilers involved have taken pains to make sure they are defined with the same pragmas, for example. And passing a C++ structure between different CRTs is likely to not work at all... so i would say, if you are going to use different CRTs in the same program, make sure that any structure you pass to a CRT was also obtained from that CRT.... don't cross streams.... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I know it's possible because I have tested it. But what I want to know is is it safe to do so. As I know Orange C programs will link with Orange C's own CRT and GCC programs will link with GCC's own CRT. Is it safe to mix different CRT in the same program?
Beta Was this translation helpful? Give feedback.
All reactions