* Namespaces & main()
@ 1998-10-10 18:34 Gerald Gutierrez
1998-10-11 22:21 ` Alexandre Oliva
0 siblings, 1 reply; 10+ messages in thread
From: Gerald Gutierrez @ 1998-10-10 18:34 UTC (permalink / raw)
To: EGCS List
Hi all. I'm not very familiar with C++ namespaces yet so perhaps the
following may be correct behaviour. If so, please let me know.
If I try compiling the following :
namespace A { void main () { } }
namespace B { void main () { } }
egcs 1.1b gives me the following :
/tmp/ccNoTIxu.s: Assembler messages:
/tmp/ccNoTIxu.s:27: Fatal error: Symbol main already defined.
but if I renamed them to something else, like fmain(), then the code
compiles fine.
Alternatively, if I have the following :
namespace C {
void main () { }
namespace D {
void main () { }
}
}
I get :
/tmp/cc84q10E.s: Assembler messages:
/tmp/cc84q10E.s:27: Fatal error: Symbol main already defined.
as well. If I rename them to something else, the code compiles fine.
Is this correct C++ behaviour or is this something wrong with egcs ?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Namespaces & main()
1998-10-10 18:34 Namespaces & main() Gerald Gutierrez
@ 1998-10-11 22:21 ` Alexandre Oliva
1998-10-14 6:09 ` Branko Cibej
0 siblings, 1 reply; 10+ messages in thread
From: Alexandre Oliva @ 1998-10-11 22:21 UTC (permalink / raw)
To: Gerald Gutierrez; +Cc: EGCS List
Gerald Gutierrez <gutier@intergate.bc.ca> writes:
> namespace A { void main () { } }
> namespace B { void main () { } }
> /tmp/ccNoTIxu.s: Assembler messages:
> /tmp/ccNoTIxu.s:27: Fatal error: Symbol main already defined.
> Is this correct C++ behaviour or is this something wrong with egcs ?
It's a bug in egcs. main() is only reserved in the global namespace,
according to [basic.start.main]/3. I've installed your testcase in
the testsuite.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:oliva@gnu.org mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Namespaces & main()
1998-10-11 22:21 ` Alexandre Oliva
@ 1998-10-14 6:09 ` Branko Cibej
1998-10-15 18:57 ` Todd Vierling
0 siblings, 1 reply; 10+ messages in thread
From: Branko Cibej @ 1998-10-14 6:09 UTC (permalink / raw)
To: Alexandre Oliva; +Cc: EGCS List
Alexandre Oliva wrote:
> Gerald Gutierrez <gutier@intergate.bc.ca> writes:
>
> > namespace A { void main () { } }
> > namespace B { void main () { } }
>
> > /tmp/ccNoTIxu.s: Assembler messages:
> > /tmp/ccNoTIxu.s:27: Fatal error: Symbol main already defined.
>
> > Is this correct C++ behaviour or is this something wrong with egcs ?
>
> It's a bug in egcs. main() is only reserved in the global namespace,
> according to [basic.start.main]/3. I've installed your testcase in
> the testsuite.
Just FYI, I tried the following:
namespace A { int main() {} }
and got
namespace-main.cc: In function `int main()':
namespace-main.cc:2: warning: control reaches end of non-void function `main()'
while the following:
int main() {}
Did not produce a warning. All of this seems OK to me.
--
Branko Cibej <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49 fax: (++386 61) 186 52 70
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Namespaces & main()
1998-10-14 6:09 ` Branko Cibej
@ 1998-10-15 18:57 ` Todd Vierling
1998-10-16 4:10 ` Andreas Schwab
[not found] ` <vyzsogoyk8f.fsf.cygnus.egcs@issan.cs.uni-dortmund.de>
0 siblings, 2 replies; 10+ messages in thread
From: Todd Vierling @ 1998-10-15 18:57 UTC (permalink / raw)
To: Branko Cibej; +Cc: Alexandre Oliva, EGCS List
On Wed, 14 Oct 1998, Branko Cibej wrote:
: namespace A { int main() {} }
: namespace-main.cc: In function `int main()':
: namespace-main.cc:2: warning: control reaches end of non-void function `main()'
: int main() {}
:
: Did not produce a warning. All of this seems OK to me.
This part is correct. The global "main" is explicitly defined in the C++
standard to return 0 if no return value is given.
--
-- Todd Vierling (Personal tv@pobox.com; Bus. todd_vierling@xn.xerox.com)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Namespaces & main()
1998-10-15 18:57 ` Todd Vierling
@ 1998-10-16 4:10 ` Andreas Schwab
1998-10-16 13:30 ` Martin von Loewis
[not found] ` <vyzsogoyk8f.fsf.cygnus.egcs@issan.cs.uni-dortmund.de>
1 sibling, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 1998-10-16 4:10 UTC (permalink / raw)
To: Todd Vierling; +Cc: Branko Cibej, Alexandre Oliva, EGCS List
Todd Vierling <tv@pobox.com> writes:
|> On Wed, 14 Oct 1998, Branko Cibej wrote:
|>
|> : namespace A { int main() {} }
|>
|> : namespace-main.cc: In function `int main()':
|> : namespace-main.cc:2: warning: control reaches end of non-void function `main()'
|>
|> : int main() {}
|> :
|> : Did not produce a warning. All of this seems OK to me.
|>
|> This part is correct. The global "main" is explicitly defined in the C++
|> standard to return 0 if no return value is given.
Unfortunately g++ doesn't implement that yet. Thus you'll currently get a
random exit code in this case.
Andreas.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Namespaces & main()
[not found] ` <vyzsogoyk8f.fsf.cygnus.egcs@issan.cs.uni-dortmund.de>
@ 1998-10-16 11:49 ` Jason Merrill
1998-10-19 1:27 ` Andreas Schwab
0 siblings, 1 reply; 10+ messages in thread
From: Jason Merrill @ 1998-10-16 11:49 UTC (permalink / raw)
To: Andreas Schwab, egcs
>>>>> Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> writes:
> |> This part is correct. The global "main" is explicitly defined in the C++
> |> standard to return 0 if no return value is given.
> Unfortunately g++ doesn't implement that yet.
Huh? Sure it does.
Jason
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Namespaces & main()
1998-10-16 4:10 ` Andreas Schwab
@ 1998-10-16 13:30 ` Martin von Loewis
0 siblings, 0 replies; 10+ messages in thread
From: Martin von Loewis @ 1998-10-16 13:30 UTC (permalink / raw)
To: schwab; +Cc: tv, branko.cibej, oliva, egcs
> |> This part is correct. The global "main" is explicitly defined in the C++
> |> standard to return 0 if no return value is given.
>
> Unfortunately g++ doesn't implement that yet. Thus you'll currently get a
> random exit code in this case.
??? On i486-pc-linux-gnu, when given
int main(){}
egcs-2.92.15 produces, with -O2 -S -fno-exceptions
-fomit-frame-pointer the output
main:
xorl %eax,%eax
ret
The bugs with 'main' in a namespace is a different issue. The name
'main' is not special inside a namespace: it is not the program entry
point, nor defaults its return value to 0.
Regards,
Martin
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Namespaces & main()
1998-10-16 11:49 ` Jason Merrill
@ 1998-10-19 1:27 ` Andreas Schwab
1998-10-19 2:16 ` Jason Merrill
0 siblings, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 1998-10-19 1:27 UTC (permalink / raw)
To: Jason Merrill; +Cc: egcs
Jason Merrill <jason@cygnus.com> writes:
|> >>>>> Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> writes:
|>
|> > |> This part is correct. The global "main" is explicitly defined in the C++
|> > |> standard to return 0 if no return value is given.
|>
|> > Unfortunately g++ doesn't implement that yet.
|>
|> Huh? Sure it does.
The last time i checked (with the 981005 snapshot) it didn't. Maybe that
changed in the mean time.
Andreas.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Namespaces & main()
1998-10-19 1:27 ` Andreas Schwab
@ 1998-10-19 2:16 ` Jason Merrill
1998-10-21 3:27 ` Andreas Schwab
0 siblings, 1 reply; 10+ messages in thread
From: Jason Merrill @ 1998-10-19 2:16 UTC (permalink / raw)
To: Andreas Schwab; +Cc: egcs
>>>>> Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> writes:
> Jason Merrill <jason@cygnus.com> writes:
> |> >>>>> Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> writes:
> |>
> |> > |> This part is correct. The global "main" is explicitly defined
> |> > |> in the C++ standard to return 0 if no return value is given.
> |>
> |> > Unfortunately g++ doesn't implement that yet.
> |>
> |> Huh? Sure it does.
> The last time i checked (with the 981005 snapshot) it didn't. Maybe that
> changed in the mean time.
Just to be clear, I'm talking about falling off the end of ::main being
equivalent to a 'return 0;'. g++ has supported this since before I started
working on it in 1993.
Jason
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Namespaces & main()
1998-10-19 2:16 ` Jason Merrill
@ 1998-10-21 3:27 ` Andreas Schwab
0 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 1998-10-21 3:27 UTC (permalink / raw)
To: Jason Merrill; +Cc: egcs
Jason Merrill <jason@cygnus.com> writes:
|> Just to be clear, I'm talking about falling off the end of ::main being
|> equivalent to a 'return 0;'. g++ has supported this since before I started
|> working on it in 1993.
Hmm, i tried it again, and it works as expected. It seems like i forgot
to switch on my brain when i checked the last time. :-(
Andreas.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~1998-10-21 3:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-10 18:34 Namespaces & main() Gerald Gutierrez
1998-10-11 22:21 ` Alexandre Oliva
1998-10-14 6:09 ` Branko Cibej
1998-10-15 18:57 ` Todd Vierling
1998-10-16 4:10 ` Andreas Schwab
1998-10-16 13:30 ` Martin von Loewis
[not found] ` <vyzsogoyk8f.fsf.cygnus.egcs@issan.cs.uni-dortmund.de>
1998-10-16 11:49 ` Jason Merrill
1998-10-19 1:27 ` Andreas Schwab
1998-10-19 2:16 ` Jason Merrill
1998-10-21 3:27 ` Andreas Schwab
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).