entry point

Discussion in 'C Programming' started by aneesh, Jul 30, 2003.

  1. aneesh

    aneesh Guest

    Hi all,
    I would like to know whether we can specify another function instead
    of main as entry point.
    Thanks
    Aneesh
     
    aneesh, Jul 30, 2003
    #1
    1. Advertising

  2. aneesh

    Morris Dovey Guest

    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
     
    Morris Dovey, Jul 30, 2003
    #2
    1. Advertising

  3. Morris Dovey <> 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 () ---------------------------\
    | 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
     
    Joona I Palaste, Jul 30, 2003
    #3
  4. aneesh

    Morris Dovey Guest

    Joona I Palaste wrote:
    > Morris Dovey <> 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
     
    Morris Dovey, Jul 30, 2003
    #4
  5. On 30 Jul 2003 02:34:56 -0700
    (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?-*s:(putchar(45),c
    ),putchar(main(c,k+=*s-c*-1,s+1)):(s=0);return!s?10:10+*k;}
     
    Pieter Droogendijk, Jul 30, 2003
    #5
  6. 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.
     
    Martin Ambuhl, Jul 30, 2003
    #6
  7. aneesh

    Phil Guest

    Pieter Droogendijk wrote:

    > On 30 Jul 2003 02:34:56 -0700
    > (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
     
    Phil, Aug 4, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam Fields
    Replies:
    0
    Views:
    2,812
    Sam Fields
    Oct 22, 2004
  2. AtomicBob
    Replies:
    14
    Views:
    899
    Toby Inkster
    May 2, 2006
  3. Mike Owen

    Allowing entry of a Carriage Return during data entry

    Mike Owen, Jul 27, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    715
    Alessandro Zifiglio
    Jul 27, 2006
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,350
    Saraswati lakki
    Jan 6, 2012
  5. Noozer
    Replies:
    2
    Views:
    262
    Dr John Stockton
    Aug 1, 2005
Loading...

Share This Page