?
Solved

Pointer to main function

Posted on 2003-03-10
4
Medium Priority
?
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

743 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