Mail Archives: djgpp/2001/09/09/13:17:58
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 -