Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Pointer to main function

Posted on 2003-03-10
4
Medium Priority
?
168 Views
Last Modified: 2010-04-15
Hi --

I am writting a thread simulation program for a class.  I have to create a pointer to the main function in the initialization function for our thread package.  I have no clue how to do this.  My professor said something about creating a prototype for main....but Im not sure what that means.  Thanks :-)
marc
0
Comment
Question by:superarno
3 Comments
 

Accepted Solution

by:
kotkova earned 300 total points
ID: 8105319
Basically, the prototype for the Main is:

int main( int, void** );

This line of code (the prototype, must be placed before the main if you have one).

The declaration of the pointer for the main would look like this:

int(*ptr)( int, void** );

notice the similarities between return type (in thid case, int)  and parameter list (in this case ( int, void** )).

Then, just like a regular pointer, you set its value like so:
ptr = &main;

To use the pointer, you dereference it like a regular pointer, and in addition to that, you must pass the corresponding parameters just like a regular function call like so:

(*ptr)( param1, param2 );
   or
 ptr( param1, param2 );

***the "ptr" is any variable name you want, it can be "hello" like this:  int(*hello)( int, void** );

Linus
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 8120071
ptr = &main

is not mandatory. You can use this also

ptr = main
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10105159
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by kotkova.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question