public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* __main?
@ 2001-01-26  1:25 Axel Kittenberger
  2001-01-26  2:02 ` __main? Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Axel Kittenberger @ 2001-01-26  1:25 UTC (permalink / raw)
  To: gcc-help

Hi, 

I'm trying to compile a freestanding application with gcc 2.95.2
Unfortunally one of my routines is called "main", and somehow gcc seems to
handle that one specially :), however in my case this just a function like
every one else.

To be exact, after compiling that file containing the main function it stops
at linking stage with an unresolved link to "__main". I've searched
everything on this, and I'm quite certain that I never explicity refer to it with
underscores. Did gcc create that? or what is it? the _REAL_ entry point for
normal OS based applications?

btw: -ffreestanding did not help....

Regards,
- Axel

-- 
Sent through GMX FreeMail - http://www.gmx.net

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: __main?
  2001-01-26  1:25 __main? Axel Kittenberger
@ 2001-01-26  2:02 ` Alexandre Oliva
  2001-01-26  2:28   ` __main? Axel Kittenberger
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Oliva @ 2001-01-26  2:02 UTC (permalink / raw)
  To: Axel Kittenberger; +Cc: gcc-help

On Jan 26, 2001, Axel Kittenberger <Anshil@gmx.net> wrote:

> Unfortunally one of my routines is called "main", and somehow gcc seems to
> handle that one specially :), however in my case this just a function like
> every one else.

How is GCC supposed to figure it out?  main() *is* a special function
in C.  You aren't even allowed to take its address or to call it.
Don't name a regular function main().

> To be exact, after compiling that file containing the main function
> it stops at linking stage with an unresolved link to "__main".
> [...]  Did gcc create that? or what is it?

Yep.  On certain platforms, GCC arranges for main() to call __main(),
that runs static initializers.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: __main?
  2001-01-26  2:02 ` __main? Alexandre Oliva
@ 2001-01-26  2:28   ` Axel Kittenberger
  2001-01-26  3:15     ` __main? Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Axel Kittenberger @ 2001-01-26  2:28 UTC (permalink / raw)
  To: gcc-help

> How is GCC supposed to figure it out?  main() *is* a special function
> in C.  You aren't even allowed to take its address or to call it.
> Don't name a regular function main().

Possibly by -ffreestanding maybe? :o)

> Yep.  On certain platforms, GCC arranges for main() to call __main(),
> that runs static initializers.

Okay if I create a __main that's empty the linker will be happy, right?
Hmmm gcc, did not protest when I called main();....

---------------------------------------------

Other question, is gcc capable of letting me switching sections, so like
I've some few global variables that I want to reside in a special section, or
some startup code witch is required to be on the first code page?

All I've found are the macros that allow me to tell gcc how to switch
sections if it decides to do so....

-- 
Sent through GMX FreeMail - http://www.gmx.net

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: __main?
  2001-01-26  2:28   ` __main? Axel Kittenberger
@ 2001-01-26  3:15     ` Alexandre Oliva
  2001-01-26  3:40       ` __main? Axel Kittenberger
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Oliva @ 2001-01-26  3:15 UTC (permalink / raw)
  To: Axel Kittenberger; +Cc: gcc-help

On Jan 26, 2001, Axel Kittenberger <Anshil@gmx.net> wrote:

> Okay if I create a __main that's empty the linker will be happy, right?

It may work, yes.  But then, it may break later.

> Hmmm gcc, did not protest when I called main();....

Not even with -W -Wall -ansi -pedantic?

> Other question, is gcc capable of letting me switching sections, so
> like I've some few global variables that I want to reside in a
> special section, or some startup code witch is required to be on the
> first code page?

Look for `section' in ``Variable attributes'', in the GCC manual.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: __main?
  2001-01-26  3:15     ` __main? Alexandre Oliva
@ 2001-01-26  3:40       ` Axel Kittenberger
  0 siblings, 0 replies; 5+ messages in thread
From: Axel Kittenberger @ 2001-01-26  3:40 UTC (permalink / raw)
  To: gcc-help

> > Hmmm gcc, did not protest when I called main();....
> 
> Not even with -W -Wall -ansi -pedantic?

Okay throwed together following stuff:
------------------------test.c--------------------------
#include <stdio.h>          

int main(int argc, char **argv) 
{
  char *args[] = {"IT'S ME", 0};
  if (argc == 1) 
    main(2, args);
  else if (argc == 2) {
    printf(argv[0]);	
  }
  return 0;
}
-----------------------------------------------------------------------
$ gcc test.c -W -Wall -ansi -pedantic
it compiled completly silenty.... (2.95.2 on a cygwin host)

- Axel

-- 
Sent through GMX FreeMail - http://www.gmx.net

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-01-26  3:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-26  1:25 __main? Axel Kittenberger
2001-01-26  2:02 ` __main? Alexandre Oliva
2001-01-26  2:28   ` __main? Axel Kittenberger
2001-01-26  3:15     ` __main? Alexandre Oliva
2001-01-26  3:40       ` __main? Axel Kittenberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).