This is a group for folks designing and programming embedded systems using the Rabbit Semiconductor C-programmable microcontroller. Rabbit Semi is a spin-off from Z-World who makes a variety of embedded modules and tools. This group is not affiliated with either Rabbit or Z-World, but is a user forum for sharing ideas, asking questions,
flaunting knowledge, and other typical user group stuff. The Rabbit is a powerful uC, supported by a full-featured C-compiler.
Struct and data overlay - Marco Trapanese - Oct 2 12:42:21 2008
Hello,
I'm puzzling over a strange problem on an RCM4100 DC10.21.
I have two char arrays:
char ROVDATA_raw[20];
char HDUDATA_raw[20];
I fill them and I'll have data save into them, of course.
But if I declare two structs like these:
struct {
char raw[20];
int len;
} ROVDATA;
struct {
char raw[20];
int len;
} HDUDATA;
a write to HDUDATA.raw will be appended to ROVDATA.raw.
The write function is very simple. Something like:
for (i = 0; i > 10; i++) {
HDUDATA.raw[i] = i;
}
Does anyone could guess where is the bug?
Thanks
Marco / iw2nzm
------------------------------------

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )
Re: Struct and data overlay - Steve Trigero - Oct 2 13:15:50 2008
Your for loop won't do anything when using a "greater than" sign.
Are you sure that's what you want?
----- Original Message ----
From: Marco Trapanese
To: r...@yahoogroups.com
Sent: Thursday, October 2, 2008 9:42:13 AM
Subject: [rabbit-semi] Struct and data overlay
Hello,
I'm puzzling over a strange problem on an RCM4100 DC10.21.
I have two char arrays:
char ROVDATA_raw[ 20];
char HDUDATA_raw[ 20];
I fill them and I'll have data save into them, of course.
But if I declare two structs like these:
struct {
char raw[20];
int len;
} ROVDATA;
struct {
char raw[20];
int len;
} HDUDATA;
a write to HDUDATA.raw will be appended to ROVDATA.raw.
The write function is very simple. Something like:
for (i = 0; i > 10; i++) {
HDUDATA.raw[ i] = i;
}
Does anyone could guess where is the bug?
Thanks
Marco / iw2nzm

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )Re: Struct and data overlay - Kenny Millar - Oct 2 16:51:30 2008
Hi Marco,
ROVDATA and HUDATA are named type definitions, not variables.
Since they are both the same structure you could simply do this....
struct {
char raw[20];
int len;
} MYDATA;
void main()
{
auto int i;
MYDATA rov;
MYDATA hdu;
for(i=0; i<10; i++)
{
rov.raw[i]=i;
hdu.raw[i]=i;
}
}
Hope this helps...
-Kenny M.
On 2 Oct 2008, at 18:15, Steve Trigero wrote:
>
> Your for loop won't do anything when using a "greater than" sign.
> Are you sure that's what you want?
> ----- Original Message ----
> From: Marco Trapanese
> To: r...@yahoogroups.com
> Sent: Thursday, October 2, 2008 9:42:13 AM
> Subject: [rabbit-semi] Struct and data overlay
>
> Hello,
>
> I'm puzzling over a strange problem on an RCM4100 DC10.21.
> I have two char arrays:
>
> char ROVDATA_raw[ 20];
> char HDUDATA_raw[ 20];
>
> I fill them and I'll have data save into them, of course.
>
> But if I declare two structs like these:
>
> struct {
> char raw[20];
> int len;
> } ROVDATA;
>
> struct {
> char raw[20];
> int len;
> } HDUDATA;
>
> a write to HDUDATA.raw will be appended to ROVDATA.raw.
>
> The write function is very simple. Something like:
>
> for (i = 0; i > 10; i++) {
> HDUDATA.raw[ i] = i;
> }
>
> Does anyone could guess where is the bug?
>
> Thanks
> Marco / iw2nzm
>

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )RE: Struct and data overlay - Don Starr - Oct 2 17:33:16 2008
>ROVDATA and HUDATA are named type definitions, not variables.
In C, the O.P.'s:
> struct {
> char raw[20];
> int len;
> } ROVDATA;
>
> struct {
> char raw[20];
> int len;
> } HDUDATA;
most certainly creates two "variables" (i.e. allocates storage) for
structures, with the names ROVDATA and HDUDATA. Presuming those two names
are in scope, code such as:
void foo( void )
{
char i;
for ( i=0; i<10; i++ )
HDUDATA.raw[i] = i;
}
is certainly "legal". In the O.P.'s code, the only glaring problem was the
use of operator '>' in the 'for' statement. If he supplied more background
on exactly what he's trying to do, we could possibly help more.
>Since they are both the same structure you could simply do this....
------------------------------------

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )Re: Struct and data overlay - Marco Trapanese - Oct 3 1:53:35 2008
> most certainly creates two "variables" (i.e. allocates storage) for
> structures, with the names ROVDATA and HDUDATA. Presuming those two
names
> are in scope, code such as:
> void foo( void )
> {
> char i;
> for ( i=0; i<10; i++ )
> HDUDATA.raw[i] = i;
> }
>
> is certainly "legal".
Actually, the two structs are slightly different (there are few other
fields of integer type). So I don't use a typedef but create
on-the-fly the two anonymous struct vars.
> In the O.P.'s code, the only glaring problem was the
> use of operator '>' in the 'for' statement.
The '>' sign was a typo. I wasn't at office and I quickly wrote the
code without copy & paste.
> If he supplied more background
> on exactly what he's trying to do, we could possibly help more.
What I'm trying to do is very simple. Given those two structs I want
to fill them with appropriate data (received from a serial port).
Before to assign values to fields I check the data format (eg. strings
length, integers range, etc...).
Strings are correctly terminated by '\0'. After assigned the string to
one struct - let's say HDUDATA.raw - byte per byte as received from
the serial port, I'll retrieve the same data in the ROVDATA.raw.
I can't explain myself this.
When the terminator '\0' is not present I bet this behavior is correct
because it doesn't know where the string ends. But I'm pretty sure I
append a '\0' to received data.
Anyway, I'm going to work just now. I will post some pieces of actual
code (I won't post all code because is over 1500 lines and only few of
them are related to this issue).
Thanks for your answers.
Marco / iw2nzm
------------------------------------

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )
Re: Struct and data overlay - Marco Trapanese - Oct 3 3:34:02 2008
Guys, I solved.
The code was ok. I had to delete all files in the source folder and
compile again the code.
Now it works. Perhaps some files was locked and not updated.
Marco / iw2nzm
------------------------------------

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )
RE: RE: Struct and data overlay - Kenny Millar - Oct 3 5:17:10 2008
Yes - sorry you are dead right!
In my haste I read it as typdef struct.
I certainly appologise!
-K
From: r...@yahoogroups.com [mailto:r...@yahoogroups.com] On
Behalf Of Don Starr
Sent: 02 October 2008 22:33
To: r...@yahoogroups.com
Subject: [rabbit-semi] RE: Struct and data overlay
>ROVDATA and HUDATA are named type definitions, not variables.
In C, the O.P.'s:
> struct {
> char raw[20];
> int len;
> } ROVDATA;
>
> struct {
> char raw[20];
> int len;
> } HDUDATA;
most certainly creates two "variables" (i.e. allocates storage) for
structures, with the names ROVDATA and HDUDATA. Presuming those two names
are in scope, code such as:
void foo( void )
{
char i;
for ( i=0; i<10; i++ )
HDUDATA.raw[i] = i;
}
is certainly "legal". In the O.P.'s code, the only glaring problem was the
use of operator '>' in the 'for' statement. If he supplied more background
on exactly what he's trying to do, we could possibly help more.
>Since they are both the same structure you could simply do this....

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )