Re: DOS program recording it's parameters and environment?

Samuel Bronson <[email protected]>
Newsgroups org.kernel.vger.linux-msdos
Message-ID <CAJYzjmcCi_450Ph7WfTtsytujejzeT1R1HMW5xtWvLpCRSK1pQ@mail.gmail.com>
On Thu, Feb 16, 2012 at 4:01 PM, Paul Crawford <[email protected]> wrote:
> Dear Frantisek,
>
>> compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock
>> to problem - it seems as this compiler not support construction:
>>
>> int main(int argc, char *argv[], char *envp[])
>
> I think this 3rd argument may be a MS-specific extension, as most C programs
> just have argc & argv in the call to main();

This is not actually MS-specific; I see it in my execve(2) manpage
here on Linux, and
<http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B> says "Unix
(though not POSIX.1) and Microsoft Windows have a third argument
giving the program's environment". (I was actually a little surprised
to see that it wasn't POSIX.)

GNU's libc.info says so, too:

>    In Unix systems you can define `main' a third way, using three
> arguments:
>
>      int main (int ARGC, char *ARGV[], char *ENVP[])
>
>    The first two arguments are just the same.  The third argument ENVP
> gives the program's environment; it is the same as the value of
> `environ'.  See Environment Variables.  POSIX.1 does not allow this
> three-argument form, so to be portable it is best to write `main' to
> take two arguments, and use the value of `environ'.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.