Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > entry point

Reply
Thread Tools

entry point

 
 
aneesh
Guest
Posts: n/a
 
      07-30-2003
Hi all,
I would like to know whether we can specify another function instead
of main as entry point.
Thanks
Aneesh
 
Reply With Quote
 
 
 
 
Morris Dovey
Guest
Posts: n/a
 
      07-30-2003
aneesh wrote:
> I would like to know whether we can specify another function instead
> of main as entry point.


Aneesh...

I must be missing something. The file containing main need not be
named main.c - main /is/ how you specify the executable's entry
point. If you want some other function than the one you called
main to be the primary entry point, then just rename the current
main to something else and call the other function main.
--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c

 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      07-30-2003
Morris Dovey <(E-Mail Removed)> scribbled the following:
> aneesh wrote:
>> I would like to know whether we can specify another function instead
>> of main as entry point.


> Aneesh...


> I must be missing something. The file containing main need not be
> named main.c - main /is/ how you specify the executable's entry
> point. If you want some other function than the one you called
> main to be the primary entry point, then just rename the current
> main to something else and call the other function main.


Where did you see Aneesh mention main.c?

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"The question of copying music from the Internet is like a two-barreled sword."
- Finnish rap artist Ezkimo
 
Reply With Quote
 
Morris Dovey
Guest
Posts: n/a
 
      07-30-2003
Joona I Palaste wrote:
> Morris Dovey <(E-Mail Removed)> scribbled the following:
>
>>aneesh wrote:
>>
>>>I would like to know whether we can specify another function instead
>>>of main as entry point.

>
>>Aneesh...

>
>>I must be missing something. The file containing main need not be
>>named main.c - main /is/ how you specify the executable's entry
>>point. If you want some other function than the one you called
>>main to be the primary entry point, then just rename the current
>>main to something else and call the other function main.

>
>
> Where did you see Aneesh mention main.c?


Joona...

Nowhere; but suggested as a possibility by the wording of the
question. Do you think I reached too far in trying to understand
where the question was coming from?
--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c

 
Reply With Quote
 
Pieter Droogendijk
Guest
Posts: n/a
 
      07-30-2003
On 30 Jul 2003 02:34:56 -0700
http://www.velocityreviews.com/forums/(E-Mail Removed) (aneesh) wrote:
> Hi all,
> I would like to know whether we can specify another function instead
> of main as entry point.
> Thanks
> Aneesh


Yes, we can, but how it's done is linker-specific. Arguments -e and --entry for
the GNU linker, for example. Try the newsgroup for your compiler, or read
it's documentation.

--
main(int c,char*k,char*s){c>0?main(0,"adceoX$_k6][^hn","-7\
0#05&'40$.6'+).3+1%30"),puts(""):*s?c=!c?-*sputchar(45),c
),putchar(main(c,k+=*s-c*-1,s+1))s=0);return!s?10:10+*k;}
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      07-30-2003
aneesh wrote:

> Hi all,
> I would like to know whether we can specify another function instead
> of main as entry point.


Not in a hosted environment, which is what you are probably using. In a
freestanding environment, the required "designated function" to be
executed at start-up need not be named "main," although it often is.

 
Reply With Quote
 
Phil
Guest
Posts: n/a
 
      08-04-2003
Pieter Droogendijk wrote:

> On 30 Jul 2003 02:34:56 -0700
> (E-Mail Removed) (aneesh) wrote:
>
>>Hi all,
>>I would like to know whether we can specify another function instead
>>of main as entry point.
>>Thanks
>>Aneesh

>
>
> Yes, we can, but how it's done is linker-specific. Arguments -e and --entry for
> the GNU linker, for example. Try the newsgroup for your compiler, or read
> it's documentation.


Er...

On GNU/Linux the default entry point for an ELF executable is named
_start, which is library function contained in libgcc_s (or sometimes
libc on older systems). _start hoiks the command and arguments out of
the OS-defined ABI positions and reformats them to the correct C ABI
positions for argc, argv (and argp, but lets not talk about that), then
calls main.

A similar bit of sysabi-specific code deals with the return vale of main
(or the argument ot exit()), it's usually called _exit.

So in fact, yes you can define the entry point to any symbol you desire,
_but_ you will be replacing _start and not main, and you almost
certainly don't want to do that.

I'd personally go for either a wrapper main function, or quicker but
dirtier, adding -Dmyfun=main to the preprocessor flags (CPPFLAGS).

Phil

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
Allowing entry of a Carriage Return during data entry Mike Owen ASP .Net Web Controls 3 07-27-2006 02:34 PM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
Form field entry directs to diff URLs based on entry? AtomicBob HTML 14 05-02-2006 07:07 AM
Clear ATM0.1 point-to-point entry. AM Cisco 2 02-04-2005 10:38 AM



Advertisments