Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: srand(0) Date: Wed, 31 Dec 2025 16:00:45 -0800 Organization: None to speak of Lines: 40 Message-ID: <87ldiiurpu.fsf@example.invalid> References: <10ib0ka$3cgil$1@dont-email.me> <10icocl$3u4ua$1@dont-email.me> <10idg5m$3k87$3@dont-email.me> <20251224105114.0000714b@yahoo.com> <10ih0qo$13hnn$2@dont-email.me> <20251224174452.00003278@yahoo.com> <10ih3lu$13hnn$5@dont-email.me> <10ih5r2$25ihh$5@dont-email.me> <10iiell$1kfhj$1@dont-email.me> <10iirh8$25ihh$6@dont-email.me> <10ilfqp$2fs21$1@dont-email.me> <10ivq6b$1j8r3$1@dont-email.me> <10j206j$27s3j$1@dont-email.me> <10j247s$2925s$3@dont-email.me> <87fr8rwccq.fsf@example.invalid> <10j3mit$2o18r$1@dont-email.me> <10j3qr4$2p2od$1@dont-email.me> <10j42kv$2s72e$6@dont-email.me> <10j49pi$2v0l9$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Thu, 01 Jan 2026 00:00:46 +0000 (UTC) Injection-Info: dont-email.me; posting-host="33b043e89e5f39dc06c7cc358565192e"; logging-data="3106480"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Rn+4fih2QZPOIjZ4qfQXY" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:7Adrmt7fdEXCLNncjEUemjGJJ2w= sha1:s+SU/hCj/gI/a6xJMAiLoOqrgc4= Xref: csiph.com comp.lang.c:396048 bart writes: [...] > argv[0] merely returns what was typed on the command line to invoke the application. > > So if someone types: > > C:\abc> prog > > it may run a prog.exe found in, say, c:\programs\myapp, and return the full path as > "c:\programs\myapp\prog.exe". > > args[0] will give you only "prog"; good luck with that! [...] That's typically how it works, but it's not guaranteed. If a program is invoked from a shell on a Unix-like system, the shell will use something like fork() and one of the exec() functions, and will typically (perhaps always?) arrange for the new process's argv[0] to point to a copy of the program name given on the shell command line. (Programs that behave differently depending on the string pointed to by argv[0] are typically invoked via symbolic links, so for example vi and view might be names for the same executable.) But there are a number of other ways to invoke programs. In the example I posted, a C program calls execve() directly, and sets up argc and argv in a way that a shell would never do. For safety, any program should safely handle being invoked with unusual arguments -- especially any program with extra privileges. For simplicity, it could simply abort if argc==0 and/or argv[0]==NULL. Similar considerations probably apply on Windows, though it seems that Windows tries to guarantee argc>1 and argv[0]!=NULL. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */