delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/08/03/11:47:53

X-Spam-Check-By: sourceware.org
Message-ID: <44D21A8E.7090708@scytek.de>
Date: Thu, 03 Aug 2006 11:47:26 -0400
From: Volker Quetschke <quetschke AT scytek DOT de>
User-Agent: Thunderbird 1.5.0.5 (Windows/20060719)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Is casting away const OK for cygwin's execvp
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------enigE05EBFFE4CB3396CB0BACEE8
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi

I encountered this when writing some c++ program that uses execvp
to start another process.

Basically (see the attached example program)

  int execvp(const char *path, char * const *argv);

the prototype of execvp() doesn't like constant char arrays for the second
parameter, but that's what you get when you use the c_str() function
on strings.

Googling for this problem didn't help beside the point that it, depending
on the implementation, is save on some architectures to "cast away"
the const because the parameters are copied by execvp and therefore the
new process cannot change them in its parent.

Is it save with g++ on cygwin to to this?

   execvp(nargv[0], const_cast<char * const *>(nargv) )
--------------------^^^^^^^^^^^^^^^^^^^^^^^^^^

(Yes, I know that I can just copy the const char* into new char*
arrays but this includes extra memory and overhead and the parameter
lists of the application where the code comes from can get rather long
and the program is called very often so that I would like to avoid that.)

I would appreciate some insight here.


   Volker

--=20
PGP/GPG key  (ID: 0x9F8A785D)  available  from  wwwkeys.de.pgp.net
key-fingerprint 550D F17E B082 A3E9 F913  9E53 3D35 C9BA 9F8A 785D


--------------enigE05EBFFE4CB3396CB0BACEE8
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (MinGW)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFE0hqWPTXJup+KeF0RArYVAJ97ANHemHuBa51JYvo3HxeTc7kW/QCfSftZ
LHD2UmGmHtsy65Rbtc5EtuI=
=Aovv
-----END PGP SIGNATURE-----

--------------enigE05EBFFE4CB3396CB0BACEE8--

- Raw text -


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