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: <004201c1675a$261ae960$38810142@pavilion> From: "J. J. Farrell" To: Subject: Global variables - was: Re: [PATCH proposal] Re: Setup use on win2k - a me too ... Date: Tue, 6 Nov 2001 23:02:20 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="x-user-defined" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 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. -- 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/