Re: Questions about 64bits portability
- From: "Fuochi" <nospam@xxxxxxxxxx>
- Date: Fri, 15 Dec 2006 09:47:23 +0100
thanks for all these very good feedbacks !
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> a écrit dans le message de
news: kn43o2di3bpdjo3jjtvisvageuc95slgn6@xxxxxxxxxx
See below...
On Thu, 14 Dec 2006 17:36:16 +0100, "Fuochi" <nospam@xxxxxxxxxx> wrote:
Hello,****
I am totally newbee in the migration of 32 bits app to 64 bits. I have
some
questions regarding the portability :
is the following code correct under x64 :
1 - in a list control when setting a item data with a base type
========================================
int i=1 ;
listCtrl.SetItemData(0, (DWORD_PTR)i) ;
int k = (int)listCtrl.GetItemData(0) ;
As long as you know the value really is only a 32-bit range, then the
above code works
well. Unfortunately, Microsoft is a bit confused about some uses of
length, so they'll
specify things like an 'int' length (thus allowing for negative lengths, a
fascinating
concept for data structures) but if you use sizeof() you will get warnings
about
truncation. In an intelligent world, lengths would have been defined from
the beginning
as size_t values.
****
****
2 - structure arithmetic pointers
========================
newNameRecord and currentRecord are 2 pointers to a structure class as
function parameters
void funct(mystruct* newNameRecord, mystruct* currentRecord)
{
DWORD dwBufSize = (DWORD)((LPBYTE)newNameRecord -
(LPBYTE)currentRecord)
You should use DWORD_PTR here, simply because it is possible in Win64 to
have arrays
longer than 4.2GB. Frankly, I'd tend to avoid any implementation strategy
in which the
above could be written, but that's because I like robustness. The above
code seems
amazingly fragile, and in any case I would tend to use things which are
based on either
MFC collections or std:: collections, and avoid address arithmetic
whenever possible (I
tend to think in a model of managed code even though I write native apps)
****
;****
3 - retrieve a value in a byte array
========================
void funct(LPBYTE lpBuffer)
{
DWORD dwSize = (*((DWORD*)lpBuffer));
Again, DWORD_PTR or SIZE_T would be a better choice here, but that's
because you have used
the word "Size" in your variable. Anything that expresses a size should
be thought of as
requiring 64 bits. If this is part of a file, the file should use 64 bit
lengths even in
a 32-bit app so that it can be read by a 64-bit app (note that a 64-bit
app could
potentially write files a 32-bit app couldn't read, but in that case you
simply have to
say "data structure too large". If the size is, by its formal
specification, limited to
32 bits, then the above code is fine; in fact, there is nothing related to
64 bits at all
in such a case.
****
****
The value was stored using :
memcpy_s ( lpBuffer, dwBuffSize, &dwSize, sizeof(DWORD) );
How it was stored is irrelevant. What it means is relevant. Bits are
just bits until you
attempt to assign meaning to them.
****
thanksJoseph M. Newcomer [MVP]
Cedric
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Questions about 64bits portability
- From: Fuochi
- Re: Questions about 64bits portability
- From: Joseph M . Newcomer
- Questions about 64bits portability
- Prev by Date: unhandled exeception error 0xC0000005 while debugging
- Next by Date: Search Column & Row using CMap, Lookup
- Previous by thread: Re: Questions about 64bits portability
- Next by thread: Re: Simple extension of CEdit
- Index(es):
Relevant Pages
|