It is currently Tue, 07 Dec 2021 02:05:53 GMT



 
Author Message
 static functions in library matching global functions
I have a peculiar problem which I'm sure you gurus can answer.

I've created a full-blown Motif widget for Solaris 2.5.1 and I've compiled
it into a dynamic shared library so that I can use it in multiple programs.

The problem is, however, that some of the static functions in the library
have the same names as public functions in the application that uses the
library, and at runtime the library calls the global functions instead of
its own static functions!

I thought that static stuff were renamed so that it would not be accessible
nor possibly match other functions. If, for instance, a static variables in
two object modules have the same name, how do the compiler know which one to
use, and when? But if functions are renamed, how come the application
manages to call the wrong functions?

Is the behavior perhaps different when compiling a library (I'm using cc
4.2)? Is there a switch I can use to make the library call the correct
static functions?

Please help, as I don't know how to solve this problem (other than the
obvious; renaming the functions, of course (which is not a good solution
since I can never be 100% sure whether some other program has global
functions with the same names...).

--
Ketil Hunn



 Sat, 19 Oct 2002 03:00:00 GMT   
 static functions in library matching global functions
You are correct static functions and variables will overide any
global ones.  Compiling into a shared or static library won't
effect this.

As for your problem...
Maybe you defined the static function too far down in your
source.  static functions and file level static variables only
have scope from their definition to the end of the file.
You might be able to fix this behavior by adding function
prototypes for the static functions to the top of the source
file.  If you turn on warning massages you can have the compiler
tell you when you are missing a prototype.

Good luck!
Alan

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



 Sat, 19 Oct 2002 03:00:00 GMT   
 static functions in library matching global functions

news:36c4c0ea.a183d6b0@usw-ex0105-034.remarq.com...

This is not the case here, the global ones are overriding the static ones!
All static functions are prototyped at the top of the source, but when I set
a breakpoint inside one of the static functions that "matches" a global
funciton, the static one is never called.

--
Ketil Hunn



 Sun, 20 Oct 2002 03:00:00 GMT   
 static functions in library matching global functions
On Wed, 3 May 2000 12:21:23 +0200 Ketil Hunn <Ketil.H...@protek.no> wrote:

| news:36c4c0ea.a183d6b0@usw-ex0105-034.remarq.com...
|> You are correct static functions and variables will overide any
|> global ones.  Compiling into a shared or static library won't
|> effect this.
|
| This is not the case here, the global ones are overriding the static ones!
| All static functions are prototyped at the top of the source, but when I set
| a breakpoint inside one of the static functions that "matches" a global
| funciton, the static one is never called.

Try defining, not just prototyping, the static functions at the top.
When I put static functions in my code, I put them all at the top and
don't even bother with prototypes since the definition fills in that
information for the remaining scope.  If any static functions call
others, order them so references go up (circular references may be
a problem here).

--
| Phil Howard - KA9WGN | My current boycotts: Amazon.Com, DVDs, Mattel, Sony
| phil-nos...@ipal.net +----------------------------------------------------
| Dallas - Texas - USA | My current websites: linuxhomepage.com, ham.org



 Fri, 01 Nov 2002 03:00:00 GMT   
 
   [ 4 post ] 

Similar Threads

1. Global initialization function in a library?

2. function, function...who's got the function?

3. how to strip/hide a global symbol in a static library

4. Accessing global variables from shared/dynmaic functions.

5. ksh88: Setting global integer within function

6. debian, m68k: HELP PROBLEM: global register variable follows a function definition

7. awk and match function

8. nawk & match() function

9. Problems linking static library on executable and static library


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software