Sep.29.2017 -- CAlive to introduce parameter redirects

4 views
Skip to first unread message

Rick C. Hodgin

unread,
Sep 29, 2017, 8:49:31 AM9/29/17
to caliveprogra...@googlegroups.com
CAlive will introduce the ability to automatically redirect an incoming parameter to other variables with the to keyword using the simple syntax to name.  Multiple targets can also be specified using commas with to name1, name2, ... nameN.  Each target type will be auto-converted using typesco conversions where defined, and standard casts where not defined.

Multiple new targets from a single input parameter can also be created by using the syntax to { int name1, float name2, double name3 }, where, in this example, three new variable copies of the single input parameter are automatically created by CAlive.

Note: The ability to auto-convert/cast an incoming parameter to multiple types also creates the possibility of calling a function with multiple input parameter types, creating multiple port entry points for the function, as an incoming float to-directed to an int and a float shares the same function use ability as an incoming int to-directed to an int and a float.

Note:  The ability to create multiple targets with to {...} is distinct from and different than the implicit union { type1 name1, type2 name2, ... typeN nameN } declaration syntax due to the present of the leading keyword to.

    // Illustrative function
    printf("Result = %d\n", abc(1, 2, 3));

    // Traditional form
    function abc
    | params int a, int b, int c
    | returns int r
    {
        r = (a * b) + c;
    }

    // Using to on the 3rd parameter
    function abc
    | params int a, int b, to r
    | returns int r
    {
        // Note:  At entry, r has already been auto-populated with the 3rd parameter's value.
        //        To complete the computation, only (a * b) needs to be added.
        r += (a * b);
    }    

Note:  This functionality was introduced to allow processing of <meta> and <mefa> casks more easily in flow blocks:

    // Assume success
    lnResult = 0;
    flow
    {
        <|mefa|error(-1)||>  do_something1();
        <|mefa|error(-2)||>  do_something2();

    } error(to lnResult) {
        // Note:  The incoming parameter (-1 or -2) will be auto-copied to lnResult
        flowout;
    }

    // Indicate our result
    return(lnResult);

Traditional code:

    // Assume success
    lnResult = 0;
    do
    {
        if (!do_something1())
        {
            lnResult = -1;
            break;
        }
        if (!do_something2())
        {
            lnResult = -2;
            break;
        }

    } while (0);

    // Indicate our result
    return(lnResult);

Thank you,
Rick C. Hodgin

Reply all
Reply to author
Forward
0 new messages