• Missing argv[0]?

    From Nick@21:1/5 to All on Wed Dec 20 15:10:49 2023
    I've been playing around with Aztec-C 1.06D on the RunCPM emulator and
    I've been unable to get the programs to print argv[0] (the name of the
    calling program). I eventually found in the Aztec-C manual an
    explanation that says this is a null pointer in CP/M.

    Is this the same for all CP/M versions, was it enhanced in any of the
    other CCPs?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Schultz@21:1/5 to Nick on Wed Dec 20 10:52:54 2023
    On 12/20/23 9:10 AM, Nick wrote:
    I've been playing around with Aztec-C 1.06D on the RunCPM emulator and
    I've been unable to get the programs to print argv[0] (the name of the calling program). I eventually found in the Aztec-C manual an
    explanation that says this is a null pointer in CP/M.

    Is this the same for all CP/M versions, was it enhanced in any of the
    other CCPs?

    CP/M-68K gives you a pointer to "C Runtime". That might be true but I
    can't recall ever checking.

    The problem stems from the BDOS copying the command tail to the default
    DMA buffer as part of its setup before starting the program. That does
    not include the program name so it isn't available to the C runtime code
    that sets up the argv array.

    --
    http://davesrocketworks.com
    David Schultz

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Nick@21:1/5 to David Schultz on Thu Dec 21 11:08:31 2023
    On 20/12/2023 16:52, David Schultz wrote:
    On 12/20/23 9:10 AM, Nick wrote:
    I've been playing around with Aztec-C 1.06D on the RunCPM emulator and
    I've been unable to get the programs to print argv[0] (the name of the
    calling program). I eventually found in the Aztec-C manual an
    explanation that says this is a null pointer in CP/M.

    Is this the same for all CP/M versions, was it enhanced in any of the
    other CCPs?

    CP/M-68K gives you a pointer to "C Runtime". That might be true but I
    can't recall ever checking.

    The problem stems from the BDOS copying the command tail to the default
    DMA buffer as part of its setup before starting the program. That does
    not include the program name so it isn't available to the C runtime code
    that sets up the argv array.


    OK I've had the chance to test a bit further on CP/M 2.2 and CP/M-86
    with the same results so I'll find a workaround. I was playing with some
    old code for Motorola 6800 series assemblers and found it works with DOS
    but not under various CP/M versions. Plus it's been an interesting
    learning exercise as I've never been much of a C programmer.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Nick@21:1/5 to Mark Ogden on Sat Jan 20 15:46:19 2024
    On 22/12/2023 09:56, Mark Ogden wrote:
    On Thursday 21 December 2023 at 11:08:37 UTC, Nick wrote:
    On 20/12/2023 16:52, David Schultz wrote:
    On 12/20/23 9:10 AM, Nick wrote:
    I've been playing around with Aztec-C 1.06D on the RunCPM emulator and >>>> I've been unable to get the programs to print argv[0] (the name of the >>>> calling program). I eventually found in the Aztec-C manual an
    explanation that says this is a null pointer in CP/M.

    Is this the same for all CP/M versions, was it enhanced in any of the
    other CCPs?

    CP/M-68K gives you a pointer to "C Runtime". That might be true but I
    can't recall ever checking.

    The problem stems from the BDOS copying the command tail to the default
    DMA buffer as part of its setup before starting the program. That does
    not include the program name so it isn't available to the C runtime code >>> that sets up the argv array.

    OK I've had the chance to test a bit further on CP/M 2.2 and CP/M-86
    with the same results so I'll find a workaround. I was playing with some
    old code for Motorola 6800 series assemblers and found it works with DOS
    but not under various CP/M versions. Plus it's been an interesting
    learning exercise as I've never been much of a C programmer.
    The historic technique to provide argv[0] or equivalent, was to code it in the source code.
    Whitesmiths compilers for example used _pname to store the program name, and the usage function would show this
    Hi-Tech uses the prompt name passed into _getargs. By default it defines nularg i.e. "". It could easily be changed to use a user defined string similar to Whitesmiths approach
    Mark


    Thanks.
    I've now had a chance to test a later MS-DOS version 4.10D of Aztec C I
    found on Bitsavers in the pdf/manx directory. Interestingly, it doesn't
    print argv[0] on that OS so maybe it's a Manx thing as well as CP/M.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)