From owner-freebsd-hackers@FreeBSD.ORG Sun Feb 13 13:23:05 2011 Return-Path: Delivered-To: hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 16F0B106566C for ; Sun, 13 Feb 2011 13:23:05 +0000 (UTC) (envelope-from mandree@FreeBSD.org) Received: from unimail.uni-dortmund.de (mx1.HRZ.Uni-Dortmund.DE [129.217.128.51]) by mx1.freebsd.org (Postfix) with ESMTP id 977CE8FC1C for ; Sun, 13 Feb 2011 13:23:04 +0000 (UTC) Received: from webmail.tu-dortmund.de (vmx028.itmc.tu-dortmund.de [129.217.131.82]) by unimail.uni-dortmund.de (8.14.4/8.14.4) with ESMTP id p1DCxcEC022785; Sun, 13 Feb 2011 13:59:39 +0100 (CET) Received: from 77.5.78.247 (SquirrelMail authenticated user smmaandr) by webmail.tu-dortmund.de with HTTP; Sun, 13 Feb 2011 13:59:38 +0100 Message-ID: Date: Sun, 13 Feb 2011 13:59:38 +0100 From: "Matthias Andree" To: "Julian H. Stacey" User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Cc: hackers@FreeBSD.org Subject: Re: man 3 getopt char * const argv[] - is const wrong ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Feb 2011 13:23:05 -0000 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 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