• INMOS C compiler Version 2.01.10 pitfall

    From Mike B.@21:1/5 to All on Mon Feb 6 14:58:46 2023
    Hi!

    I like to reuse the arguments of a C function passed by value. Why waste space. BUT - don't do that with the function arguments for a process!

    #include <process.h>
    #include <stdlib.h>
    #include <stdio.h>

    void newproc( Process *p, int arg1, int arg2, int arg3 ) {
    p = p;
    printf( "arg1=%d, arg2=%d, arg3=%d\n", arg1, arg2, arg3 );
    arg3--;
    arg2++; /* don't change process arguments even they were passed by value !!! */
    }

    int main( void ) {

    Process *x;
    int pa1 = 1, pa2 = 2, pa3 = 3;

    if (( x = ProcAlloc( newproc, 0, 3, pa1, pa2, pa3 )) == NULL ) abort();

    ProcPar( x, NULL );
    ProcPar( x, NULL );
    ProcPar( x, NULL );

    return 0;
    }

    ubuntu@kria:~$ $ISERVER -sb proc.btl
    arg1=1, arg2=2, arg3=3
    arg1=1, arg2=3, arg3=2
    arg1=1, arg2=4, arg3=1

    -Mike

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From cpm@21:1/5 to All on Tue Feb 7 13:16:46 2023
    Hi Mike,

    I agree that ProcAlloc and ProcPar may not be what a C programmer would expect. ProcAlloc allocates and initializes the process according to the documentation. The function creates the process structure and sets the initial values.
    ProcPar runs the process. In your case, you ran it three times in sequence without re-initializing.
    The result we see seems reasonable.
    If you want to reuse the process, you can reinitialize it with ProcInit.

    Claus

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