Sponsored Content
Top Forums Programming question about Function pointers Post 302472135 by Corona688 on Tuesday 16th of November 2010 11:01:38 AM
Old 11-16-2010
The syntax to use a function pointer is a little tricky, but the concept isn't hard at all if you know what a pointer is. It's just a pointer, that points to a function, because functions reside in memory too.

When you call a function name in C, what you're actually doing is calling an address in memory where the function's code resides. Most of the linker's job is to figure out where everything should go and substitute appropriate addresses for names. So, whenever you call a function, it actually ends up as a hardcoded address...

It's also possible to call an arbitrary address; for instance, if you loaded a dynamic library, you have to use function pointers to call functions from it since you won't know what they will be until the library's loaded. It works the same as far as the code's concerned. It just uses a pointer value you give it, instead of hardcoding one.
This User Gave Thanks to Corona688 For This Post:
 

9 More Discussions You Might Find Interesting

1. Programming

Sharing C++ Objects with virtual function table pointers

I am pondering the next question: Can I safely sare objects that have virtual functions (i.e. have virtual function table pointers) between two processes ? Where will the pointers point to in each process ? What I am afraid of is that in the creating process the pointer will indeed point to... (2 Replies)
Discussion started by: Seeker
2 Replies

2. Shell Programming and Scripting

Question about function

/ (6 Replies)
Discussion started by: jy2728
6 Replies

3. UNIX for Dummies Questions & Answers

Date function question

hi guys! just want to ask if you could help me with the sript i'm working on. i need to automatically generate a summarized report everyday for all transactions the day before and ftp it to another machine. my only problem is that i need to name the file as the date yesterday. for example if i... (12 Replies)
Discussion started by: crpalermo
12 Replies

4. Programming

Regarding Function and Pointers.

HI, Here is some thing that is puzzling me from a long time. Can some body explain me this with example. The question is :- What is the difference between function pointer and pointer to a function. Where do we actually use the function pointers and pointer to functions. Thanks in... (0 Replies)
Discussion started by: S.Vishwanath
0 Replies

5. Programming

Question about the system() function in C

Hello all ! Could someone throw some light on whether there's a limit to the number of characters contained in the command string that is passed to the system() call in C. Is it OS dependent? If yes, what are the limits for each? Thanks. (4 Replies)
Discussion started by: vsanjit
4 Replies

6. Programming

Question with pointers and free()

Just a statement I need some clarification Im aware that malloc() can be used to create pointers, and free() is used to deallocate dynamic memory, however is free() the ONLY way to dispose of the dynamic memory, because not using free() means the dynamic memory still exists and it may cause some... (1 Reply)
Discussion started by: JamesGoh
1 Replies

7. Shell Programming and Scripting

Question about Function calls

Hello everyone, here's my problem: I want to create two shell scripts. one of them should includes some functions, the other one just the function calls. Is this possible? Can i call a function which is placed in a scriptfile eg functions.sh out of another script eg call.sh? :confused: And if... (2 Replies)
Discussion started by: Sebi0815
2 Replies

8. Programming

question about function object

I have a code as following: #include <iostream> #include <algorithm> #include <list> using namespace std; //the class Nth is a predicates class Nth{ private: int nth; int count; public: Nth(int n):nth(n),count(0){} bool operator()(int){ ... (2 Replies)
Discussion started by: homeboy
2 Replies

9. Programming

How to Declare an array of function pointers?

I am attempting to create an array of function pointers. The examples I follow to do this are from: support.microsoft.com/en-us/help/30580/how-to-declare-an-array-of-pointers-to-functions-in-visual-c ... (3 Replies)
Discussion started by: spflanze
3 Replies
mitem_new(3X)															     mitem_new(3X)

NAME
mitem_new - create and destroy menu items SYNOPSIS
#include <menu.h> ITEM *new_item(const char *name, const char *description); int free_item(ITEM *item); DESCRIPTION
The function new_item allocates a new item and initializes it from the name and description pointers. Please notice that the item stores only the pointers to the name and description. Those pointers must be valid during the lifetime of the item. So you should be very carefull with names or descriptions allocated on the stack of some routines. The function free_item de-allocates an item. Please notice that it is the responsibility of the application to release the memory for the name or the description of the item. RETURN VALUE
The function new_item returns NULL on error. The function free_item returns one of the following: E_OK The routine succeeded. E_SYSTEM_ERROR System error occurred (see errno). E_BAD_ARGUMENT Routine detected an incorrect or out-of-range argument. E_CONNECTED Item is connected to a menu. SEE ALSO
curses(3X), menu(3X). NOTES
The header file <menu.h> automatically includes the header file <curses.h>. PORTABILITY
These routines emulate the System V menu library. They were not supported on Version 7 or BSD versions. AUTHORS
Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S. Raymond. mitem_new(3X)
All times are GMT -4. The time now is 07:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy