The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
main makefile ideur UNIX for Dummies Questions & Answers 6 12-19-2007 04:56 AM
Main Resursive is it possible krishna_sicsr High Level Programming 7 04-09-2007 08:13 AM
How to go to main prompt amitra123 HP-UX 2 09-03-2004 01:38 PM
c++ calling main() function norsk hedensk High Level Programming 3 01-22-2003 08:28 PM
How do I input an argument in the main? yhosun High Level Programming 2 06-11-2002 09:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-26-2006
arun.viswanath arun.viswanath is offline
Registered User
  
 

Join Date: Jun 2005
Location: INDIA
Posts: 13
main function

Is it possible to execute any function before main() function in C or C++.
  #2 (permalink)  
Old 04-26-2006
gauravgoel gauravgoel is offline
Registered User
  
 

Join Date: Dec 2005
Location: India
Posts: 218
just a small doubt why you are looking for somthing like this.

as per my knowledge its not possible
  #3 (permalink)  
Old 04-26-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
after the entry pt of an exe it is the main function that is called first ( actually loaded into stack trace )

i am not sure of this,

if you want some other function to execute first
then you need to have your exe generator, with options to work at the entry pt level of any exe
  #4 (permalink)  
Old 04-26-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
The C standard says that a module called "_start" runs first, then calls main().
You can usually see it in the output from nm:
Code:
_sr4export          |      6968|extern|code   |$CODE$
_start              |          |undef |code   |
_start              |      6512|uext  |stub   |
_tepv               |1073746360|undef |common |$BSS$
You can create your own version of start if you want, then link against it.

Why you would want to do this... I don't know.
  #5 (permalink)  
Old 04-26-2006
mcady_02 mcady_02 is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 4
Shoot me if Im wrong, but wouldn't it just be easier to have main() call your function before anything else?
  #6 (permalink)  
Old 04-29-2006
mxms755 mxms755 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 22
try it out

hi
this might be a way but on my machine(linux) it didnt worked
anyway try it out
use

#pragma start
some_function()
{
printf("hi\n");
}

main()
{
printf("hello\n");
}

ideally it should give the output as
hi
hello
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0