memory allocation problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robannexs@gmail.com

    #1

    memory allocation problems

    Hi all,

    Ilets say i have this structure

    struct cbw read_command_re quest;
    char buffer[32];

    read_command_re quest.signature =0x43425355;
    read_command_re quest.tag=0x82A 36008;
    read_command_re quest.tlength=0 x24;
    read_command_re quest.flags=0x8 0;
    read_command_re quest.cbwlun=0; //'1
    read_command_re quest.clength=0 x06;
    read_command_re quest.operation _code=0x12;
    read_command_re quest.lun=0; //'32 '=1
    read_command_re quest.lba=0x002 40000;
    read_command_re quest.reserved= 0x00;
    read_command_re quest.blocks=0x 0000;
    read_command_re quest.controls= 0x00;
    read_command_re quest.padding1= 0x0000;
    read_command_re quest.padding2= 0x0000;
    read_command_re quest.padding3= 0x0000;

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

  • Bill Pursell

    #2
    Re: memory allocation problems


    robannexs@gmail .com wrote:
    struct cbw read_command_re quest;
    char buffer[32];
    >
    read_command_re quest.signature =0x43425355;
    read_command_re quest.tag=0x82A 36008;
    <snip>
    how do i move my data from read_command_re quest 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.

    --
    Bill Pursell

    Comment

    • Flash Gordon

      #3
      Re: memory allocation problems

      Bill Pursell wrote:
      robannexs@gmail .com wrote:
      >
      >struct cbw read_command_re quest;
      >char buffer[32];
      >>
      >read_command_r equest.signatur e=0x43425355;
      >read_command_r equest.tag=0x82 A36008;
      <snip>
      >how do i move my data from read_command_re quest 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.
      --
      Flash Gordon

      Comment

      Working...