Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <146801c196f9$0929c500$0200a8c0@lifelesswks> From: "Robert Collins" To: , "Hiroo Hayashi" Cc: References: <20020106 DOT 143454 DOT 47902771 DOT hiroo DOT hayashi AT computer DOT org> <3C38BE6C DOT 1080300 AT ece DOT gatech DOT edu> Subject: Re: progamming with Cygwin GNU Readline Library Date: Mon, 7 Jan 2002 08:28:07 +1100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-OriginalArrivalTime: 06 Jan 2002 21:30:07.0506 (UTC) FILETIME=[4FED4F20:01C196F9] ----- Original Message ----- From: "Charles Wilson" > > Yep, this is a windows DLL problem. You can't use the address of an > imported variable as a static initializer, because it isn't constant. > It will depend on where the DLL is loaded into memory at each runtime. > (I'm pretty sure of that; Corrections, anyone? Robert?) Correct. Tech details follow. Worse than that. The address of imported variables (without decoration) is actually resolved to the address of the offset in the (IIRTC) IAT (Import Address Table). So the _value_ that you'd read from that variable would be equivalent to reading from a union of a void * and your data type. When you tell GCC to import a dll variable it internally considers that to be a ( *). I.e. if you are importing a "(struct foo) *" from a .dll, then while your code shows struct foo * mypointertofoo; mypointertofoo->bar=3; GCC translates this into something along the lines of struct foo ** mypointertofoo; (* mypointertofoo)->bar=3; And a corollary of this is that taking a static initializer is impossible - what is the static value of "(* mypointertofoo)"? (When "* mypointertofoo" is the value from the IAT + the loaded base address). The only way around this that I know of is to assign the address to your static pointer at the beginning of main. And also, AFAIK auto-import cannot solve this, as while the value of the statically initialised IAT member is resolveable, the application will crash if/when the .dll relocates. I'm not sure if gcc detects this or not. Rob -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/