Thread: extern static?

  1. #1
    Horrifically Generic User
    Join Date
    Aug 2005
    Posts
    3

    extern static?

    Hey there. I originally intended on casually starting out this post and eventually drawing towards my problem with a few metaphors and chuckesome comments, but I decided against it. ;) So here's my conundrum:

    Entity.cpp
    Code:
    static void Entity_Callback()
    {
      // Blah..
    }
    And in my header..

    Entity.h
    Code:
    extern static void Entity_Callback()
    So that other source files can access the function. However, my compiler assures me that this would mean "more than one storage class specified". I'm a bit perturbed by this, so I was hoping that the gurus lingering around here would be able to shed some light on how I may achieve the desired effect.

    Thanks! :)

  2. #2
    Banned
    Join Date
    Jun 2005
    Posts
    594
    maybe you should put the whole function in the .h file
    using extern, and it should be viewable to all the soruce files.

  3. #3
    Horrifically Generic User
    Join Date
    Aug 2005
    Posts
    3
    Quote Originally Posted by ILoveVectors
    maybe you should put the whole function in the .h file
    using extern, and it should be viewable to all the soruce files.
    That would be rather unwieldy/awkward. Is there any way of doing what I'm trying to accomplish?

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    static functions/variables are invisible outside of the file where they're defined, takes it out of the whole global namespace. That's kind of what the keyword is for I think. So I would think that using the extern keyword to say that it is defined in another file would cause some clashing in the compilers head, I don't know ifthere would be a way to fix it without just removing the keyword..
    Last edited by Tonto; 08-15-2005 at 10:30 PM. Reason: awkward

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Just remove 'static' from both of them, problem solved.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Horrifically Generic User
    Join Date
    Aug 2005
    Posts
    3
    Quote Originally Posted by Salem
    Just remove 'static' from both of them, problem solved.
    Genius. I hope everybody around here isn't this "useful".

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >shed some light on how I may achieve the desired effect
    The desired effect being? It looks like you want a function to be visible only in the file that it's declared in, but you also want other files to be able to see it as well. I'm sorry to say, but with C++, it's all or nothing. You don't have control over who sees what at the global scope. However, since static global functions are a deprecated feature anyway, why not take advantage of namespaces? You won't force the function to be invisible, but the the reason behind your "desired effect" is most likely name clashes, which a namespace would solve.

    >I hope everybody around here isn't this "useful".
    If everyone around here were as useful as Salem then I would have a much less cynical view of the programming community in general.
    My best code is written with the delete key.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > how I may achieve the desired effect.
    Well how about actually stating what you wanted rather than just wandering into a forum, spouting off some half-assed question then flaming anyone who isn't psychic enough to figure out that the answer is PEBKAC?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Quote Originally Posted by Salem
    > how I may achieve the desired effect.
    Well how about actually stating what you wanted rather than just wandering into a forum, spouting off some half-assed question then flaming anyone who isn't psychic enough to figure out that the answer is PEBKAC?
    Quite right, JadedProgrammer. Salem's suggestion was entirely acceptable considering the complete mystery that is your intent. Think for a moment, before you attempt to belittle others attempting to provide assistance, about what precisely you stated in your post. Essentially, you pointed out a compiler error and asked, "How do I achieve the desired effect?" Well, sir, perhaps if you had enough sense to mention W.T.F. your intent is, those of us offering input might have something worthy of your audience. In the interim, take a deep breath and CTFD.

    Salem: I think in this bloke's case it'd be best stated PEBSAS (Sinus and Scalp).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  5. Replies: 16
    Last Post: 10-29-2006, 05:04 AM