Skip to content

Instantly share code, notes, and snippets.

@pavly-gerges
Created May 1, 2025 04:47
Show Gist options
  • Save pavly-gerges/5ca3aadf58e18d88d75e5b2e725593e4 to your computer and use it in GitHub Desktop.
Save pavly-gerges/5ca3aadf58e18d88d75e5b2e725593e4 to your computer and use it in GitHub Desktop.

Here is an example of a non-null terminated list:

#include <stdio.h>
#include <stddef.h>

typedef struct buffer (buffer);

struct buffer {
    void *start_address;
    void *end_address;
};

static inline void print(buffer *__buffer) {
    // preprocessing automata -- Input Validation
    if (NULL == __buffer) {
        return ;
    } 
    
    void *_address = __buffer->start_address;
    for (int i = 0; NULL != _address; _address = (__buffer->start_address + i)) {
        
        // processing
        const char c = *((const char *)_address);
        printf("%c\n", c);
        
        // post-processing 
        if (__buffer->end_address == _address) {
            return ;
        }
        i++;
    }
}

int main() {
    char test[] = {'H', 'e', 'l', 'l', 'o'};
    buffer _buf = {
        .start_address = &test[0],
        .end_address = &test[4]
    };
    print(&_buf);

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment