User Block help

In the fragment below, I cannot understand why I cannot use a declaration
of “int testnum2” . . . which tells me that i do not understand “struct” (and possibly a whole lot more. I’m using an OP7200 but that shouldn’t matter . . . Any help here would be much appreciated. And border on the enlightening :):slight_smile:

/******************************************************
adapted from userblock_sample.c Z-World, 2002
******************************************************/
#class auto

#if _USER
#error “User block access not provided under RabbitSys.”
#endif

void main(void)
{
// a structure for our test data
struct
{
int testnum1;
long testnum2; // WHY CAN THIS NOT BE INT ???
} test_data;

// arrays for pointers to the data and data lengths
void* save_data[2];
unsigned int save_length[2];

//initialize test data
test_data.testnum1 = 60;
test_data.testnum2 = 70;

// see what we are saving
printf("test_data.testnum1 = %d
", test_data.testnum1);
printf("test_data.testnum2 = %d
", test_data.testnum2);

// put data into arrays & write to user block
save_data[0] = &test_data;
save_length[0] = sizeof(test_data);
writeUserBlockArray(0, save_data, save_length, 2);

// clear variables
test_data.testnum1 = 0;
test_data.testnum2 = 0;

// read back saved values
readUserBlockArray(save_data, save_length, 2, 0);

// what we found
printf("test_data.testnum1 = %d
", test_data.testnum1);
printf("test_data.testnum2 = %d
", test_data.testnum2);

}

three things:

  • I upgraded from v 9.40 to v 9.62 of DC . . . MUCH less buggy.

  • In some of my attempts to get this to work there was an error in formatting in one of my printf statements.

  • If you try to read the block before writing the block, you need to put
    save_data[0] = &blk_sav_dat;
    save_lens[0] = sizeof(blk_sav_dat);
    before you call the first
    readUserBlockArray(save_data, save_lens, 1, 0);

thanks to Rabbit Tech Support :slight_smile:

bob moore