|
-
Feb 13th, 2003, 08:31 PM
#1
Probably just a blackout
I have two pieces of code supposed to do the same thing (read an unsigned 32-bit big-endian integer from a memory stream):
Code:
return dword(
((static_cast<dword>(*source++)) << 24)
| ((static_cast<dword>(*source++)) << 16)
| ((static_cast<dword>(*source++)) << 8)
| ((static_cast<dword>(*source++)) )
);
Code:
dword d1, d2, d3, d4;
d1 = *source++;
d2 = *source++;
d3 = *source++;
d4 = *source++;
dword ret = (d1 << 24) | (d2 << 16) | (d3 << 8) | d4;
return ret;
However the second one works and the first always returns 0. Why?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 16th, 2003, 10:12 AM
#2
Addicted Member
as a relative newb to C++, I doubt I'll be helping.
Is it anything to do with "*source++" being "++*source"?
No? ok.
Using Visual Studio .NET 2005
-
Feb 16th, 2003, 11:40 AM
#3
No. It's not the same, and this piece of code is the same for both.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 16th, 2003, 12:10 PM
#4
transcendental analytic
The increment seems to be done after the statement.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Feb 16th, 2003, 12:40 PM
#5
But what are the parenthese doing there then?
But you could be right...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 16th, 2003, 12:48 PM
#6
transcendental analytic
I've tested it, the first byte is dereferenced each time
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Feb 16th, 2003, 01:23 PM
#7
damn
ok, I'll experiment with it
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|