From owner-freebsd-hackers@FreeBSD.ORG Tue Jul 22 04:54:39 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A80AA37B401 for ; Tue, 22 Jul 2003 04:54:39 -0700 (PDT) Received: from hexagon.stack.nl (hexagon.stack.nl [131.155.140.144]) by mx1.FreeBSD.org (Postfix) with ESMTP id A194543F85 for ; Tue, 22 Jul 2003 04:54:38 -0700 (PDT) (envelope-from marcolz@stack.nl) Received: by hexagon.stack.nl (Postfix, from userid 65534) id 23D2E1C38; Tue, 22 Jul 2003 13:54:37 +0200 (CEST) Received: from turtle.stack.nl (turtle.stack.nl [2001:610:1108:5010:2e0:81ff:fe22:51d8]) by hexagon.stack.nl (Postfix) with ESMTP id 945BA1C0F; Tue, 22 Jul 2003 13:54:32 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 333) id 85CA81CC56; Tue, 22 Jul 2003 13:54:32 +0200 (CEST) Date: Tue, 22 Jul 2003 13:54:32 +0200 From: Marc Olzheim To: Tim Kientzle Message-ID: <20030722115432.GA36870@stack.nl> References: <3F1B0610.90803@acm.org> <20030720225041.GA26277@ussenterprise.ufp.org> <3F1C0C91.6050203@acm.org> <20030721165735.GA56766@ussenterprise.ufp.org> <20030721171538.GA21656@colnta.acns.ab.ca> <20030721172321.GA57666@ussenterprise.ufp.org> <20030721174206.GA21892@colnta.acns.ab.ca> <3F1C2FEB.4070801@acm.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3F1C2FEB.4070801@acm.org> X-Operating-System: FreeBSD turtle.stack.nl 5.1-BETA FreeBSD 5.1-BETA X-URL: http://www.stack.nl/~marcolz/ User-Agent: Mutt/1.5.4i X-Spam-Status: No, hits=-5.0 required=5.0 tests=EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT_MUTT version=2.55 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) cc: hackers@freebsd.org cc: Chad David Subject: Re: Correct way to call execve? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Jul 2003 11:54:39 -0000 On Mon, Jul 21, 2003 at 11:24:43AM -0700, Tim Kientzle wrote: > Chad David wrote: > >I assumed it was obvious that you could copy the data, but I believe > >the intent of the original question was to find an alternative. As > >far as I know there isn't one. A const is a const, except in C++. > > Yes, the intent was to find a way to avoid copying the data. > > I was hoping that someone knew a standard way to > say "yes, I really do mean to cast away that const," > akin to C++ const_cast. > > As far as I can tell, the POSIX-mandated declaration > of execvp is simply wrong. (SUSv3 even has a comment > that essentially admits this fact and then vainly tries > to rationalize it. ) I mailed this a long time ago: char * func(void) { char *foo; const char *cfoo = "bar"; /* From http://www.eskimo.com/~scs/C-faq/q11.10.html: * * References: ANSI Sec. 3.1.2.6, Sec. 3.3.16.1, Sec. 3.5.3 * ISO Sec. 6.1.2.6, Sec. 6.3.16.1, Sec. 6.5.3 * H&S Sec. 7.9.1 pp. 221-2 * * Use -Wcast-qual with gcc. * gcc 2.7.2.3 ok, gcc 2.95.2 not ok. */ foo = *((char *const *) &cfoo); return (foo); } But that doesn't work after 2.7.2 What does work, except with 2.95 is this: foo = *((char **)((void *)&cfoo))); Then again: you can always use the union trick: union { void *nonconst; const void *constant; } hack; hack.constant = cfoo; foo = hack.nonconst; Zlo