You know, my own thinking made me figure this one out:

% cat exec.c

#include <unistd.h>
#include <paths.h>
#include <string.h>

int main(int argc, char *const argv[], char *const envp[]) {
  char *const execargv[] = { _PATH_BSHELL, NULL };

  execve(_PATH_BSHELL,execargv,NULL);

  return 0;
}
% cc -fwritable-strings -Wcast-qual -Wwrite-strings exec.c
%

There you go.  By default strings are read-only, and indeed smart
compilers use that to compress them and do other nifty tricks.  However,
in this case you really want a string to be "char *", eg writable.
So, tell the compiler to do that with "-fwritable-strings", poof,
strings are now "char *", the cast away the cost problem goes away,
"-Wcast-qual" works fine.

It always seemed to me a lot of things included -fwritable-strings for
no good reason, maybe this is part of the reason. :)

-- 
       Leo Bicknell - [EMAIL PROTECTED] - CCIE 3440
        PGP keys at http://www.ufp.org/~bicknell/
Read TMBG List - [EMAIL PROTECTED], www.tmbg.org

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to