Mail Archives: djgpp-workers/1996/08/12/06:06:18
On Thu, 1 Aug 1996, Eli Zaretskii wrote:
>
> On Thu, 1 Aug 1996, DJ Delorie wrote:
>
> > conio already handles this by using C++ constructors, which get called
> > before main().
>
> How can I access variables like argc and argv from these constructors
> (without writing C++ code)? If I cannot, they aren't good enough. Also,
> how can one know in what order will these constructors be called? (Sorry,
> I never bothered to look into the mechanism which ctors and dtors use, so
> I might have just asked two dumb questions.)
>
Yesterday I looked in the GCC documentation for some others and I found
a solution for the above problem, which is already supported by gcc. You
should declare your function with the constructor-attribute:
---sample file----
int val = 0;
void dummy() __attribute__ ((constructor));
void dummy()
{
val = 35467;
}
void main()
{
printf("%d\n",val);
}
--- end of sample file----
I think this can be also done for the conio function, because I think
it looks much betther than the actual implementation. For accessing
the arc and argv variables you can uses the __crt0_argc and __crt0_argv,
which are defined in 'crt1.c'. The order of calling the functions
in the .ctor sections depends in my opinion on the order how they
are linked.
Robert
- Raw text -