www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/09/09/13:17:58

From: Leif Leonhardy <leif AT dtcs DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: In getopt.c wht is place declared as const
Date: Sun, 09 Sep 2001 19:09:06 +0200
Organization: delta t Computerservice
Lines: 39
Message-ID: <3B9BA232.827BAC85@dtcs.de>
References: <lvR6$iAbUXm7EwSj AT cweeks DOT demon DOT co DOT uk> <3B99AB68 DOT 19D91FCB AT dtcs DOT de> <F5c9SWAgy1m7Ew3r AT cweeks DOT demon DOT co DOT uk>
NNTP-Posting-Host: pd9e0e278.dip0.t-ipconnect.de
Mime-Version: 1.0
X-Trace: news.online.de 1000055320 26422 217.224.226.120 (9 Sep 2001 17:08:40 GMT)
X-Complaints-To: abuse AT online DOT de
NNTP-Posting-Date: 9 Sep 2001 17:08:40 GMT
X-Mailer: Mozilla 4.01 [de] (Win95; I)
X-Priority: 3 (Normal)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Cameron Weeks schrieb:
> I fact this may lead back to a more general question, to completely quote the code
> it is declared as:
> 
> #define EMSG    ""
> static const char *place = EMSG;
> 
> Now surely this is a slightly dangerous thing to do. If EMSG was anything but ""
> then you would be writing to memory pointed to by an un-initialised pointer,
> therefore risking a crash. Also the rest of the getopt.c code doesn't give the
> address of place to any external functions, so why bother using const ?
Why not? If you intend not to change any strings pointed to by 'place',
let the
compiler print an error message if you (or someone else modifying the
code) do
it erroneously.
> 
> Also your bit of code did print 10,000 times, but I got the idea, I think you ment:
> 
> >       void say_hello()
> >       { static int i=0;
> >
> >         for(;i<10;i++)
		^^^^^^^^^^Shame on me, of course I meant that
			(not re-initializing i in the loop), my
			keyboard was just too fast...

> >           printf("Hello, world\n");
> >        }
> >
> >       main()
> >       { int n;
> >
> >         for(n=0;n<1000;n++)
> >           say_hello();
> >
> >         return 0;
> >       }
Leif

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019