Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #326

Re: can Variable initialized by function?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From pasa<pasa@lib.hu>
Newsgroups comp.std.c++
Subject Re: can Variable initialized by function?
Date Sat, 15 Oct 2011 09:28:09 -0700 (PDT)
Organization http://groups.google.com
Lines 21
Sender std-cpp-request@vandevoorde.com
Approved stephen.clamage@oracle.com
Message-ID <79be454a-1f36-4e15-a72d-e8ef6fbb462d@s14g2000vbj.googlegroups.com> (permalink)
References <7008aaa3-2d64-42c0-933e-14046782d918@i28g2000yqn.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
X-Trace news.albasani.net ZMQMMyAzD/r96xpO7Hnep88wNQdkIIQVgAvfEW7IcIYXYWt20cC88VXXRk1VQtU4z0RiOUPIvAb4ee5iZIxgOg==
NNTP-Posting-Date Sat, 15 Oct 2011 16:28:10 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="1hHr4Q4Vlr76gOcNvrHbIsF1dNtkcDP3XV4He2wVSpt/uHqIXnrxdqv0q7n7C3GDEaV8nkp/MttQJLP9jEM8N0lJdItif0q0uvhM0qyPYv1BPDEl/HU1Wrgrc4uoYgRw"; mail-complaints-to="abuse@albasani.net"
X-Mailer Perl5 Mail::Internet v2.05
X-Submission-Address std-cpp-submit@vandevoorde.com
Cancel-Lock sha1:SACEZEKQQ3fCoPLGcbwFilUTe3A=
X-Original-Date Sat, 15 Oct 2011 01:33:46 -0700 (PDT)
Xref x330-a1.tempe.blueboxinc.net comp.std.c++:326

Show key headers only | View raw


"Evan Zeng"<evanzengcn@gmail.com>

at global scope:
>       int i=func(1,2);
>  And it compiled sucessefully  by g++, while has  error by gcc. Can
>  anyone explain it in details?

This is good in C++ and uses dynamic init before entering main(),
calling
func() to provide initial value of i.

But C has only static init, you can only use initializers vith
constant
expression, so the compiler can figure out the value right ahead.


-- 
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Find similar


Thread

can  Variable initialized by function? Evan Zeng<evanzengcn@gmail.com> - 2011-10-07 16:08 -0700
  Re: can  Variable initialized by function? Daniel Krügler<daniel.kruegler@googlemail.com> - 2011-10-08 09:36 -0700
  Re: can Variable initialized by function? pasa<pasa@lib.hu> - 2011-10-15 09:28 -0700

csiph-web