On Tue, 22 Dec 2009, Andi Jahja wrote:
Hi,
> With the new start-up codes, I tried to make it work with Digital Mars C Mode
> but so far I achieved no success.
> I know that Digital Mars is not supported due to math bug, but this exercise
> may be a fun.
> Followings are documentation for DMC pragmas which may relate to this subject.
> Perhaps you could help making DMC C Mode working then.
When C++ code is compiled DMC stores pointers to void(*)(void) functions
used to initialize static variables in "XIFM", "XIFL" or "XIFU" segments.
The segment depends on
#pragma init_seg (<level>)
where <level> is compiler ("XIFM"), lib ("XIFL") or user ("XIFU")
At application startup DM CRTL executes startup functions taking
addresses from "XIFM" then "XIFL" and finally form "XIFU" segments.
So all what we need is pragma to control data segment, i.e.:
#include <stdio.h>
void init_func( void )
{
printf( "init function\n" );
}
int main( void )
{
printf( "main function\n" );
return 0;
}
#pragma data_seg( "XIFU" )
void ( * _func_ ) ( void ) = init_func;
#pragma data_seg()
but I do not see such pragma in official DMC documentations and also
seems that it's inline assembler does not allow to set data segments.
We only have:
#pragma code_seg( <"seg"> )
but it can be usable only if there is a code section executed by DM
CRTL at startup. I.e. in most of ELF formats .init section has such
functionality. If DMC has such segment then it's enough to make sth
like:
#include <stdio.h>
void init_func( void )
{
printf( "init function\n" );
}
int main( void )
{
printf( "main function\n" );
return 0;
}
#pragma code_seg( "INIT" ) // set valid segment name here
__declspec(naked) static void _start_( void )
{
asm call init_func
}
#pragma code_seg()
In summary we need method to set data segment or name of code segment
executed at startup of course if such segment is supported by DMC.
In both cases we need sth what is not officially documented and I'm
afraid it's all what I can say about it after short checking code
generated by DMC.
best regards,
Przemek
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour