Message-ID: <39D546B8.2310@home.com> From: "Salvador I. Ducros" X-Mailer: Mozilla 3.04 (Win95; U) MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: question about linker behaviour Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 73 Date: Sat, 30 Sep 2000 01:49:14 GMT NNTP-Posting-Host: 24.65.65.104 X-Complaints-To: abuse AT home DOT net X-Trace: news1.rdc2.on.home.com 970278554 24.65.65.104 (Fri, 29 Sep 2000 18:49:14 PDT) NNTP-Posting-Date: Fri, 29 Sep 2000 18:49:14 PDT Organization: Excite AT Home - The Leader in Broadband To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hello all. I've been unable to get a straight forward answer from my usual sources of "expert" information so I thought I'd throw this question out to UseNet. My question is basically whether or not the linker (let's say the DJGPP linker specifically) will include a function from a static library into an executable if: 1. the address of the function is assigned to some function pointer 2. the function pointer is never actually derefernced 3. the function is never called by name For example, lets say there is some data structure that contains one or more function pointers like below: typedef struct DS { void *data; unsigned long datalen; int (*fn1)(struct DS *); int (*fn2)(struct DS *); int (*fn3)(struct DS *); } DS; Why? The arbitrary data in the structure would be manipulated by the functions fn1, fn2 and fn3 which would assigned to the structure at some point where the nature of the data is known. Therefore one set of functions from possibly many sets of functions is chosen and the data can be manipulated in a generic way. So lets say all the appropriate functions are in a static library and at some point in a program such a data structure is created and three distinct functions (say A, B & C) from the library are assigned to the function pointers. Lets say further that in the entire program only one of these pointers is ever actually dereferenced (i.e. the function is called). e.g. ... ds = malloc( sizeof(DS) ); ... ds->fn1 = A; ds->fn2 = B; ds->fn3 = C; ... ds->fn2( ds ); free( ds ); ... In my example above, library function 'B' is called by dereferencing the function pointer 'fn2' of structure 'ds'. Say that none of the library functions are ever called by name [i.e. A(ds) or B(ds) or C(ds)] and say also that for whatever reason the function pointers 'fn1' and 'fn3' are never dereferenced (i.e. the functions are never called). Q: Is the linker able to detect that the library functions A & C are never executed? And, even if the linker could detect this, would the linker still include the functions A & C in the final executable? My intuition tells me yes (all three functions would be included) and the experiments I've run seem to confirm it but my "expert" sources mostly tell me no, hence my question. Anybody have any insights? Salvador I. Ducros sducros AT cdn-net DOT com