envp and extern char **environ

This is a discussion on envp and extern char **environ within the Linux Programming forums, part of the Platform Specific Boards category; What's the difference between environ and envp? They both seem to do the same thing... environ Code: #include <stdio.h> #include ...

  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, 02:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21