473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

memcpy with size of block UINT64 type

1
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 .......
Nov 23 '07 #1
3 4998
AHMEDYO
112 100+
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.

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. UINT64 V1=200;
  4. UINT64 V2=0;
  5. memcpy((void*)&V2,(void*)&V1,sizeof(UINT64));
  6. cout << (unsigned int)V1 << endl; // just print low int value
  7. cout << (unsigned int)V2 << endl; // just print low int value
  8. return 0;
  9. }
  10.  
or if i miss something please reply with more explanation.

Kind Regards
Nov 23 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
int main()
{
UINT64 V1=200;
UINT64 V2=0;
memcpy((void*)&V2,(void*)&V1,sizeof(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.
Nov 24 '07 #3
Banfa
9,065 Expert Mod 8TB
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.
Nov 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Bren | last post by:
Can anybody tell me what is wrong with this code? void SystemModule::AddModuleDependency(PTR_MODULE_INFO pModuleInfo) { if (!pModuleInfo) return; PTR_MODULE_INFO pDest = 0; if...
8
by: codefixer | last post by:
Hi, I was wondering what factors will influence the maximum buffer sizes for source and destination for memcpy(). Is their any limit to the sizeof the buffer(hardware restricting it ?) OR any...
3
by: ishmael4 | last post by:
I dont know what to do with this function. It separates a block of binary data into blocks, and then deals with the rest of binary (les than 5000 bytes). Here we go: --cut here-- void...
33
by: Case | last post by:
#define SIZE 100 #define USE_MEMCPY int main(void) { char a; char b; int n; /* code 'filling' a */
1
by: John Smith | last post by:
Hello Whenever I try to set a value of a System.UInt64 I get: Dim var1 As System.UInt64 = &H18B377544DD23334 Error BC30311: Value of type 'Long' cannot be converted to 'System.UInt64'. ...
8
by: Kevin | last post by:
Dim X as int32 Dim Y as int64 X = Y / 1024 gives me the error: "Operator is not valid for type 'UInt64' and type 'Integer'." I'm new to VB.NET and this is one of the reasons why I've...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
4
by: 2b|!2b==? | last post by:
My C appears to be more rusty than I thought, after several years in the C++ camp. I have a data structure that I want to make a copy of. Here are the details: struct MyStructA { char barney;...
14
by: somenath | last post by:
Hi All, I am trying to understand the behavior of the memcpy and memmove. While doing so I wrote a program as mentioned bellow . #include<stdio.h> #include<stdlib.h> #include<string.h> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.