memory allocation problems

R

robannexs

Hi all,

Ilets say i have this structure

struct cbw read_command_request;
char buffer[32];

read_command_request.signature=0x43425355;
read_command_request.tag=0x82A36008;
read_command_request.tlength=0x24;
read_command_request.flags=0x80;
read_command_request.cbwlun=0; //'1
read_command_request.clength=0x06;
read_command_request.operation_code=0x12;
read_command_request.lun=0; //'32 '=1
read_command_request.lba=0x00240000;
read_command_request.reserved=0x00;
read_command_request.blocks=0x0000;
read_command_request.controls=0x00;
read_command_request.padding1=0x0000;
read_command_request.padding2=0x0000;
read_command_request.padding3=0x0000;

how do i move my data from read_command_request such that when I do a
&buffer i will get 43 42 53 55 .....00 00 00 00 ?
 
B

Bill Pursell

struct cbw read_command_request;
char buffer[32];

read_command_request.signature=0x43425355;
read_command_request.tag=0x82A36008;
how do i move my data from read_command_request such that when I do a
&buffer i will get 43 42 53 55 .....00 00 00 00 ?

You're best bet is with something like memcpy(), but you may
get 55 53 42 43, depending on the endian-ness of the machine.
 
F

Flash Gordon

Bill said:
struct cbw read_command_request;
char buffer[32];

read_command_request.signature=0x43425355;
read_command_request.tag=0x82A36008;
how do i move my data from read_command_request such that when I do a
&buffer i will get 43 42 53 55 .....00 00 00 00 ?

You're best bet is with something like memcpy(), but you may
get 55 53 42 43, depending on the endian-ness of the machine.

Or you may have padding between the fields especially as it looks from
the way the OP wrote the code as though some of them could be narrower
than an int (0x00 *implies* the programmer thinks it is being assigned
to an 8 bit char type).

So the best bet if you want something that will work correctly is to
copy the data over a field at a time and within each field a byte at a time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top