memcpy with size of block UINT64 type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hiamol
    New Member
    • Nov 2007
    • 1

    memcpy with size of block UINT64 type

    as u kno memcpy has 3rd argument which is unsigned int, but i have a situation where it is UINT64, now i am not able to call memcpy as it gives warning: possible lass of data,
    is there any way handling this .......
  • AHMEDYO
    New Member
    • Nov 2007
    • 112

    #2
    HI..

    you have variable with UINT64 type, but i think variable address is still use pointer address size as any pointer for example like INT, UINT64 is 8 bytes variable and INT is 4 bytes but pointer is same for example in 32-bit environemt all is 4 bytes address, then where is the problem when using memcpy when memcpy use address not value, or you try to give memcpy the value of the variable not the address!!!, and this mean you try to use 8 byte address pointer!!!!

    this code is work well.

    [CODE=cpp]
    int main()
    {
    UINT64 V1=200;
    UINT64 V2=0;
    memcpy((void*)& V2,(void*)&V1,s izeof(UINT64));
    cout << (unsigned int)V1 << endl; // just print low int value
    cout << (unsigned int)V2 << endl; // just print low int value
    return 0;
    }
    [/CODE]
    or if i miss something please reply with more explanation.

    Kind Regards

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Originally posted by AHMEDYO
      int main()
      {
      UINT64 V1=200;
      UINT64 V2=0;
      memcpy((void*)& V2,(void*)&V1,s izeof(UINT64));
      cout << (unsigned int)V1 << endl; // just print low int value
      cout << (unsigned int)V2 << endl; // just print low int value
      return 0;
      }
      Avoid using memcpy in C++. All of the C mem... functions do not call copy constructors or assignment operators and becuase of that these guys can screw your C++ code up big time.

      Ditto for malloc/calloc/free, etc.

      And, don't forget, the C string library has been replaced with the STL string class.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by hiamol
        as u kno memcpy has 3rd argument which is unsigned int, but i have a situation where it is UINT64, now i am not able to call memcpy as it gives warning: possible lass of data,
        is there any way handling this .......
        Write you own version of memcpy that has the parameters you require. The problem is that if you pass a UNIT64 whose value is large than will fit in a size_t the value will be truncated and you will not copy as much data as you want to.

        Comment

        Working...