Mar.28.2017 -- CAlive to introduce pre {..} blocks, presizeof(), prenew, and predelete

20 views
Skip to first unread message

Rick C. Hodgin

unread,
Mar 28, 2017, 4:21:51 PM3/28/17
to caliveprogra...@googlegroups.com
CAlive will introduce named members that can be accessed before a struct or class.  These pre members do not normally exist, but can be referenced in special cases.  To allocate for them, a struct or class should be created with prenew and released with predelete, which will use the full size.  Otherwise it will only use the standard size without the pre {..} block.

    pre {
        int pa;       // Non-standard member
        int pb;       // Non-standard member

    } struct SXyz {
        int a;        // Standard member
        int b;        // Standard member
        int c;        // Standard member
    };

    // Usage in code:
    SXyz* p = new SXyz;    // Allocates a struct with only a, b, c members
    SXyz* p = prenew SXyz; // Allocates a struct with all members (pa, pb, a, b, c)

    // Member access:
    p->pa = -2;       // Access at offset -8 (can be accessed even if new was used)
    p->pb = -1;       // Access at offset -4 (can be accessed even if new was used)
    p->a  = 0;        // Access at offset 0
    p->b  = 1;        // Access at offset 4
    p->c  = 2;        // Access at offset 8

    // Total sizeof() is 12 (for members a, b, c) as the pre block members are not
    // included in the size operation.  However, if you use presizeof() you will see
    // its size reporting the full 20 bytes.
    // Note:  If accessing pre members on a non-pre block, the results are invalid

In this way, negative members can be accessed at any time, but are not part of the actual structure in use or in size.  To use the full member, use presizeof(), prenew, and predelete.

Thank you,
Rick C. Hodgin

Rick C. Hodgin

unread,
Mar 30, 2017, 1:18:11 PM3/30/17
to caliveprogra...@googlegroups.com
CAlive will also introduce a variant which allows a label to be used as a marker as to where pre-data ends using the pre: label, and to resume normal data use data:, and to use post-data using the post: label, as in:

    struct SXzy
    {
    pre:
        int pre_a;
        int pre_b;

    data:
        int a;
        int b;
        int c;

    post:   // Note:  See further in this thread for post {..} blocks
        int post_a;
        int post_b;
    };

In this case, everything defined before the pre: label will be pre-input data, and everything after the data: label will be normal data, and everything after the post: label will be post-input data.

These labels can be used as needed, and relate to everything defined after each.

Rick C. Hodgin

unread,
Jun 9, 2018, 10:21:48 AM6/9/18
to caliveprogra...@googlegroups.com
CAlive will allow pre {..} blocks to be appended before any logic or flow control block.  The pre {..} blocks explicitly tie the code to the logic or flow control block and are used for documentation and associated refactoring.

    pre {
        // You can put things here which will be tied to the for {..} block,
        // but don't take up space in the for (....)'s limited source code area

    } for (i = 0; i < 10; ++i) {
        // Normal code goes here
    }

-- 
Rick C. Hodgin

Rick C. Hodgin

unread,
Jun 16, 2018, 8:17:40 PM6/16/18
to CAlive Programming Language
CAlive will allow post {..} blocks to be appended after any logic or flow control block.  The post {..} blocks explicitly tie the code to the logic or flow control block and are used for documentation and associated refactoring.

    for (i = 0; i < 10; ++i) {
        // Normal code goes here

    } post {
        // You can put things here which will be tied to the for {..} block,
        // but don't take up space in the for (....)'s limited source code area
    } 

CAlive will also introduce named members that can be accessed after a struct or class.  These post members do not normally exist, but can be referenced in special cases.  To allocate for them, a struct or class should be created with postnew and released with postdelete, which will use the full size.  Otherwise it will only use the standard size without the post {..} block.

    struct SXyz {
        int a;        // Standard member
        int b;        // Standard member
        int c;        // Standard member

    } post {
        int pa;       // Non-standard member
        int pb;       // Non-standard member
    };

    // Usage in code:
    SXyz* p = new SXyz;     // Allocates a struct with only a, b, c members
    SXyz* p = postnew SXyz; // Allocates a struct with all members (a, b, c, pa, pb)

    // Member access:
    p->a  = 0;        // Access at offset 0
    p->b  = 1;        // Access at offset 4
    p->c  = 2;        // Access at offset 8
    p->pa = +1;       // Access at offset 12 (can be accessed even if new was used)
    p->pb = +2;       // Access at offset 16 (can be accessed even if new was used)

    // Total sizeof() is 12 (for members a, b, c) as the post block members are not
    // included in the size operation.  However, if you use postsizeof() you will see
    // its size reporting the full 20 bytes.
    // Note:  If accessing post members on a non-post block, the results are invalid

In this way, negative members can be accessed at any time, but are not part of the actual structure in use or in size.  To use the full member, use postsizeof()postnew, and postdelete.

-- 
Rick C. Hodgin

Rick C. Hodgin

unread,
Jun 16, 2018, 8:23:14 PM6/16/18
to caliveprogra...@googlegroups.com
CAlive will introduce the ability to declare both pre- and post-members to a struct or class, allowing for special access outside of the normally published data range.

    pre {
        int pre_a;    // Non-standard member
        int pre_b;    // Non-standard member

    } struct SXyz {
        int a;        // Standard member
        int b;        // Standard member
        int c;        // Standard member

    } post {
        int post_a;   // Non-standard member
        int post_b;   // Non-standard member
    };

    // Usage in code:
    SXyz* p = new SXyz;     // Allocates a struct with only a, b, c members
    SXyz* p = bothnew SXyz; // Allocates a struct with all members (pre_a, pre_b, a, b, c,
                            //                                      post_a, post_b)

    // Member access:
    p->pre_a  = -2;   // Access at offset -8 (can be accessed even if new was used)
    p->pre_b  = -1;   // Access at offset -4 (can be accessed even if new was used)
    p->a      = 0;    // Access at offset 0
    p->b      = 1;    // Access at offset 4
    p->c      = 2;    // Access at offset 8
    p->post_a = 3;    // Access at offset 12 (can be accessed even if new was used)
    p->post_b = 4;    // Access at offset 16 (can be accessed even if new was used)

    // Total sizeof() is 12 (for members a, b, c) as the pre and post block members
    // are not included in the size operation.  However, if you use bothsizeof() you
    // will see its size reporting the full 28 bytes.
    //
    // Note:  If accessing pre and/or post members on a non-pre block, the results are
    //        invalid

In this way, both negative and positive members can be accessed at any time, but are not part of the actual structure in use or in size.  To use the full member with both pre and post blocks, use allsizeof(), allnew, and alldelete.

For navigation across the larger pointers, using ++ptr and traditional pointer math will cause it to only use the sizeof() operation by default.  To use the larger size including any pre- and post-blocks, use the underscore-bang operator _!, which surrounds the pointer variable whenever used in that fashion, as in ++_ptr!, or _ptr! += 5.

-- 
Rick C. Hodgin

Reply all
Reply to author
Forward
0 new messages