3

Possible Duplicate:
Static function access in other files

IIRC, a static function is not visible outside of own "compilation unit", which I think is a .C file.

Can I pass its address as a parameter to a function in another unit so that the second unit will later invoke the first unit's static function as a callback?

I am guessing that the "visibility" of the static function is its visibility to the linker, so that, while I cannot directly invoke a static function of unit1.c in unit2.c, I can pass its address and invoke it by address.

Can anyone confirm that? Sorry, my C is a bit rusty these days. Thanks in advance for any help.

Community
  • 1
  • 1
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 2
    [This](http://stackoverflow.com/q/2182598/1410711) might be helpful.... – Recker Jan 07 '13 at 06:01
  • 2
    Certainly not a recommended technique. But yes, you can absolutely do it. Just use a function pointer. The tricky part is getting access to the address, so you can initialize the pointer. :) – paulsm4 Jan 07 '13 at 06:01
  • 4
    Yes, there's nothing that could stop you from doing that. And there is nothing non-recommended about it ... in fact, it's a recommended technique for doing callbacks, which should be static (file-local). – Jim Balter Jan 07 '13 at 06:27
  • 3
    Also, there's nothing tricky about it: just pass the name of the function as a parameter; the name (without parentheses) represents the function address. – Jim Balter Jan 07 '13 at 06:29
  • 1
    Why the heck would anyone vote to close this question? edit: ah, I see, a duplicate ... but this is a far better stated question. – Jim Balter Jan 07 '13 at 06:33

1 Answers1

2

Yes, you can call static function in that way

linuxchip
  • 316
  • 1
  • 5