Date: Sun, 13 Feb 2011 13:59:38 +0100 From: "Matthias Andree" <mandree@FreeBSD.org> To: "Julian H. Stacey" <jhs@berklix.com> Cc: hackers@FreeBSD.org Subject: Re: man 3 getopt char * const argv[] - is const wrong ? Message-ID: <c367221ee504a36fceb06e813ba6366c.squirrel@webmail.tu-dortmund.de>
next in thread | raw e-mail | index | archive | help
Am So, 13.02.2011, 13:20 schrieb Julian H. Stacey: > Hi Hackers > Ref.: man 3 getopt > int getopt(int argc, char * const argv[], const char *optstring); > Ref.: K&R 2nd Ed P.211 last indent, 2nd sentence > The purpose of const is to announce [objects] that may be > placed in read-only memory, and perhaps to increas[e] opportunities for optimization > optstring is obviously const, > but I don't see that argv can calim to be const ? Hi Julian, the prototype is in line with the Single Unix Specification v4 aka IEEE Std. 1003.1-2008 (sorry no URL, I have checked my local copy, check <http://www.opengroup.org/> you can access it free of charge after registering name and email address). The const basically states that the argv[] elements (i. e. the char * pointers) are const[ant], or, read another way, that getopt promises not to mess with the *pointers* but is free to modify the actual strings pointed to (with the usual constraints of not assuming they can be extended, for instance) - and I don't see the problem in that. Does that help? If not, please explain you confusion in a bit more detail. Best Matthias -- Matthias Andree
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c367221ee504a36fceb06e813ba6366c.squirrel>