From: nospam@needed.invalid   
      
   On Tue, 12/30/2025 10:37 PM, Keith Thompson wrote:   
   > Lawrence D’Oliveiro writes:   
   >> On Wed, 31 Dec 2025 02:01:55 -0000 (UTC), Michael Sanders wrote:   
   >>> *ISO C (C17 / C23)*:   
   >>>   
   >>> C17, 5.1.2.2.1 "Program startup"   
   >>>   
   >>> The value of argc shall be nonnegative.   
   >>>   
   >>> argv[argc] shall be a null pointer.   
   >>>   
   >>> If the value of argc is greater than zero, the array members argv[0]   
   >>> through argv[argc−1] inclusive shall contain pointers to strings   
   >>> which are given implementation-defined values.   
   >>>   
   >>> ...   
   >>>   
   >>> What say you?   
   >>   
   >> Clearly on Windows, there are no guarantees about argc contains, so   
   >> you shouldn’t be relying on it.   
   >   
   > That's not clear. Linux (since 2022) guarantees argc>=1. I don't   
   > know whether Windows makes a similar guarantee, but it's entirely   
   > plausible that it could.   
   >   
   > But not all systems guarantee argc>=1, so any portable code shouldn't   
   > make assumptions beyond what's guaranteed by ISO C.   
   >   
      
   The Windows guarantee is with MSVC, according to this answer.   
      
   ********** CoPilot Question **********   
      
   Does the Windows operating system guarantee that argc >= 1 for an EXE program ?   
      
   argv[0] usually contains the program absolute path.   
      
   ********** CoPilot Answer ************   
      
   Here’s the clear, standards‑grounded, Windows‑specific answer you’re   
   looking for — with citations from the search results.   
      
   # **Short Answer**   
   **Yes. On Windows, when using the Microsoft C runtime (MSVCRT), argc   
    is always guaranteed to be ≥ 1**, and ** argv[0] always exists**.   
   However, **Windows itself does *not* guarantee what argv[0] contains** -   
   only that the C runtime *treats* it as the program name.   
      
   ---   
      
   # **What Windows Guarantees vs. What the C Runtime Guarantees**   
      
   ### **Microsoft C Runtime Guarantee**   
   Microsoft’s documentation explicitly states:   
      
   - *“Since the program name is considered an argument, the value of argc is   
   at least one.”*   
      
   So if your EXE is built with MSVC and uses the standard main or wmain ,   
   you can rely on:   
      
   - argc >= 1   
   - argv[0] is a valid null‑terminated string   
   - argv[argc] == NULL   
      
   ### **MSVC Startup Code Behavior**   
   MSVC startup code parses the command line and   
   **always inserts the program name as argv[0] ** (quoted if needed).   
      
   ---   
      
   # **What Windows *Does Not* Guarantee**   
   Windows itself does **not** enforce that the first token of the command line   
   is the executable name. This is a convention, not a rule:   
      
   - * By convention the module name ... is the first argument ... Note that this   
   is   
    only a convention and is not enforced in any way. *   
      
   This means:   
      
   - A caller can technically pass *anything* as the first token.   
   - A process created via CreateProcess can have an arbitrary lpCommandLine .   
   - argv[0] may not be the absolute path.   
   - It may not even be a valid path at all.   
      
   This is why portable code should not assume argv[0] is the executable path.   
      
   ---   
      
   # **Cross‑Platform Note**   
   The C standard does **not** guarantee that argv[0] contains the program name   
   — only that it exists.   
   This is echoed in the search results:   
      
   - * In short: No... this is more of a common convention than a strict rule. *   
      
   ---   
      
   # **Final Summary**   
   | Question | Answe   
    |   
   |------------------------------------------------------|--------   
   ---------------------------------|   
   | **Does Windows guarantee argc >= 1 ?** | **Yes — if using   
   MSVC’s C runtime.** |   
   | **Is argv[0] guaranteed to exist?** | **Yes — with   
   MSVC.** |   
   | **Is argv[0] guaranteed to be the absolute path?** | **No.*   
    |   
   | **Does Windows enforce any of this?** | **No — it’s the C   
   runtime, not the OS.** |   
      
   If you need the *actual* executable path, use:   
      
   - GetModuleFileName(NULL, ...) (Windows API)   
      
   ---   
      
   https://learn.microsoft.com/en-us/cpp/c-language/argument-descri   
   tion?view=msvc-170&utm_source=copilot.com   
      
   https://learn.microsoft.com/en-us/cpp/c-language/parsing-c-comma   
   d-line-arguments?view=msvc-170&utm_source=copilot.com   
      
   https://github-wiki-see.page/m/johnstevenson/winbox-args/wiki/Ho   
   -Windows-parses-the-command-line?utm_source=copilot.com   
      
   https://www.codegenes.net/blog/is-argv-0-name-of-executable-an-a   
   cepted-standard-or-just-a-common-convention/?utm_source=copilot.com   
      
    When argv[0] Isn’t the Executable Name   
      
    4.1 Invocation via exec Functions   
    4.2 Symbolic Links   
    4.3 Shell Scripts and Aliases   
    4.4 Debuggers, Emulators, and Special Environments   
      
   ********** End CoPilot Answer ************   
      
    Paul   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|