/* Collection of code snippets by Arne Vajhøj */
/* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) */
#include <stdio.h>
#include <string.h>

#define BLOCKSIZE 8192
#define BLOCKS 10
#define MEMSIZ BLOCKS * BLOCKSIZE
#define MAXMSGSIZ 100
#define MAXMSGS MEMSIZ / MAXMSGSIZ

static union msgrec
{
   char dummy[MEMSIZ];
   char msg[MAXMSGS][MAXMSGSIZ];
};

#pragma extern_model save
#pragma extern_model common_block
extern union msgrec msgpsect;
#pragma extern_model restore

int main(int argc, char *argv[])
{
    int i;
    /* write to shareable image */
    i = 0;
    while(msgpsect.msg[i][0] != 0) i++;
    strcpy(msgpsect.msg[i], "Hi from C!");
    /* dump shareable image */
    for(i = 0; i < MAXMSGS; i++)
    {
        if(strlen(msgpsect.msg[i]) > 0)
        {
            printf("|%s|\n", msgpsect.msg[i]);
        }
    }
    return 0;
}
