Thread: function pointers in struct as global variable

  1. #1
    Registered User
    Join Date
    Apr 2017

    function pointers in struct as global variable

    I’m considering having a function pointer, probably more than one, in a struct. A single instance of the struct will be as a global variable. (Functions in structs as described here Function Pointer in C Struct - CodeProject ). I haven’t actually gone through the details of that yet but it appears at first glance the kind of thing I have in mind is at least possible. So then they’ll be a handful of functions attached to just one variable name. Callable from wherever. Is that a no no, or OK and good in some situations? Or just, fine but unnecessary?

    It’ll be for a bit of kind of infrastructure, functionality and data, that’ll be used throughout a system I’m trying to make. I want this infrastructure to be in the background as it were. It’ll be used here, there and everywhere, but it’s not something I want to feature prominently as I’m working on the system; hidden, just doing its job as invisibly as possible is the goal.

    Silly or OK do you reckon?


  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    I recommend that you just use well chosen function name prefixes. Unfortunately, C lacks native namespace functionality, so that is the usual solution, inflexible as it may be.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2017
    Righty hoe, OK, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 43
    Last Post: 05-23-2013, 03:01 PM
  2. How to declare a global variable in a function?
    By exclusive in forum C Programming
    Replies: 5
    Last Post: 11-06-2011, 04:28 AM
  3. global struct variable best use
    By Kempelen in forum C Programming
    Replies: 2
    Last Post: 06-05-2009, 05:08 AM
  4. Global Variable Pointers
    By incognito54 in forum C Programming
    Replies: 4
    Last Post: 04-20-2005, 11:37 AM
  5. need help acessing a global struct in function.
    By bobish in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2002, 10:32 AM

Tags for this Thread