delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1996/08/12/06:06:18

Date: Mon, 12 Aug 1996 11:52:33 +0200 (METDST)
From: Robert Hoehne <robert DOT hoehne AT mathematik DOT tu-chemnitz DOT de>
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
Cc: DJ Delorie <dj AT delorie DOT com>, djgpp-workers AT delorie DOT com
Subject: Re: Startup customization
In-Reply-To: <Pine.SUN.3.91.960801180631.5751E-100000@is>
Message-Id: <Pine.HPP.3.91.960812114451.22744D-100000@newton.mathematik.tu-chemnitz.de>
Mime-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019