PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

[FIXED] How to use execv() without warnings?

 July 17, 2022     c++, execv, g++, macos, warnings     No comments   

Issue

I am working on MacOS-X Lion with GCC 4.2. This code works, but I get a warning I would like fix:

#include <unistd.h>
main()
{
    char *args[] = {"/bin/ls", "-r", "-t", "-l", (char *) 0 };
    execv("/bin/ls", args);
}

warning: deprecated conversion from string constant to 'char*'

I do not want the warning to be suppressed, I want not to have it at all. It is C++ code, not C.

Using a char *const (so exactly the type required by execv()) still produces the warning.

Thank you.


Solution

This seems to be ok:

#include <unistd.h>
main()
{
    char const *args[] = {"/bin/ls", "-r", "-t", "-l", NULL };
    execv("/bin/ls", const_cast<char**>(args));
}


Answered By - Pietro
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing