This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Is casting away const OK for cygwin's execvp


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

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

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]