entry point

A

aneesh

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

Morris Dovey

aneesh said:
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.
 
J

Joona I Palaste

Morris Dovey said:
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 ([email protected]) ---------------------------\
| 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
 
M

Morris Dovey

Joona said:
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?
 
P

Pieter Droogendijk

On 30 Jul 2003 02:34:56 -0700
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.
 
M

Martin Ambuhl

aneesh said:
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.
 
P

Phil

Pieter said:
On 30 Jul 2003 02:34:56 -0700



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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top