Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <3BE90C31.E677AA07@syntrex.com> Date: Wed, 07 Nov 2001 11:25:53 +0100 From: Pavel Tsekov X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2-2 i686) X-Accept-Language: en MIME-Version: 1.0 To: "J. J. Farrell" CC: cygwin AT cygwin DOT com Subject: Re: Global variables - was: Re: [PATCH proposal] Re: Setup use on win2k - a me too ... References: <004201c1675a$261ae960$38810142 AT pavilion> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit "J. J. Farrell" wrote: > > Larry Hall wrote: > > At 12:06 PM 11/6/2001, Pavel Tsekov wrote: > > >Christopher Faylor wrote: > > > > > > > > It is not a bad habit to rely on global variables being 0. If they > > > > aren't then something is seriously wrong with either 'ld' or the > > > > run-time the loader. > > > > > > I didn't know this actually, so I thought it may the cause for the > > > problem. ... However the MSVC compiled programs do not have globals, > > > except the static ones, initialized to zero ... > > > > Chris' statement about zeroing out globals is important in it's > > scope but shouldn't be taken too far. Obviously, to be portable, > > adding the explicit initialization to 0 is important. Although gcc/ld > > may not require this, other compiler suites may (as you pointed out) and > > code, in general, can't assume too much about the compiler being used. > > ... > > I just wanted to make this point so that someone > > doesn't get the wrong impression about initializing globals to 0. And > > no apologies are necessary for not knowing about an obscure optimization > > feature of a compiler suite. :-) > > In C, global variables which are not explicitly initialized MUST > be initialized as if their definition includes an assignment of > an integer constant 0. This is not an obscure feature of some > compilers, it's a fundamental feature of the C language! Any > system which doesn't do this is not a conforming C environment. > Assuming that an uninitialized global variable will behave as if > its definition includes '=0' is entirely portable. > > I don't know C++, so I can't be sure it's the same. I thought I > knew of most of the situations where a conforming C program will > behave differently when compiled with a C++ compiler, and the > ones I know of are more subtle than this. I'll be amazed if C++ > differs from C on such a basic point - but I'm easily amazed. > > Pavel, can you provide an example of where MSVC doesn't do this > (perhaps to me privately rather than the list). I've never > experienced this bug, but I've only used MSVC for kernel-mode > development where different things may come into play. I did a total mess - I've refreshed my memory last night after Cristopher posted his message about globals initialization and I've found that all I wrote about the MSVC is wrong too. So this post of mine should be totally ignored. -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/