Thread: envp and extern char **environ

  1. #1
    FOX
    Join Date
    May 2005
    Posts
    188

    envp and extern char **environ

    What's the difference between environ and envp? They both seem to do the same thing...

    environ
    Code:
    #include <stdio.h>
    #include <unistd.h>
    
    extern char **environ;
    
    int main(int argc, char *argv[])
    {
            char **p = environ;
    
            while (*p != NULL)
            {
                    printf("%s (%p)\n", *p, *p);
                    *p++;
            }
    
            return 0;
    }

    envp
    Code:
    #include <stdio.h>
    
    int main(int argc, char *argv[], char *envp[])
    {
            char **p = envp;
    
            while (*p != NULL)
            {
                    printf("%s (%p)\n", *p, *p);
                    *p++;
            }
    
            return 0;
    }

  2. #2
    Climber spoon_'s Avatar
    Join Date
    Jun 2002
    Location
    ATL
    Posts
    182
    extern char **environ is the recommended way to do it now-a-days.

    no immediate differences.
    {RTFM, KISS}

  3. #3
    FOX
    Join Date
    May 2005
    Posts
    188
    I just read that extern char **environ is defined by POSIX while envp (third arg to main) is just something that a lot of implementations support.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to force a function to never return...like exec() does it
    By creeping death in forum C Programming
    Replies: 7
    Last Post: 03-28-2009, 01:08 PM