473,796 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help signed and unsigned in 64bits

Hi,

What will happen in following scenario..
long a = -2;
longlong b = a

long c;
c = *(ulonglong *)&b;
b = c;
also when
long d;
d = *&b;
b = d;
What will be the value of b ? When will it lose the upper 32bits ?

regards
amit
Nov 14 '05
25 2687
In <r2************ *************** *****@4ax.com> Leor Zolman <le**@bdsoft.co m> writes:
On Wed, 07 Apr 2004 01:13:59 GMT, Leor Zolman <le**@bdsoft.co m> wrote:

Well, that was my very first time attempting to display values of long
longs, and in my confusion I ended up with a spurious "d" in four format
conversions (I put %uld when %ul was sufficient for a plain unsigned long).
Bzzzt, still wrong. The *correct* conversion descriptor for unsigned long
is, and has always been, %lu. %ul expects an unsigned int and appends an
'l' to its value. If it receives an unsigned long, undefined behaviour.
Fortunately, that didn't really break the output, except that there's a
trailing, meaningless 'd' at the end of 4 of the lines. Sorry about that.
It broke everything, due to invoking undefined behaviour, so any output
you got was by accident, rather than by design.
P.S. It took me a while to find a platform that displayed long long values
at all! Good thing I had that Dinkum lib lying around... ;-)


It's been a common Unix extension for ages...

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #21
On 7 Apr 2004 14:09:27 GMT, Da*****@cern.ch (Dan Pop) wrote:
In <r2************ *************** *****@4ax.com> Leor Zolman <le**@bdsoft.co m> writes:
On Wed, 07 Apr 2004 01:13:59 GMT, Leor Zolman <le**@bdsoft.co m> wrote:

Well, that was my very first time attempting to display values of long
longs, and in my confusion I ended up with a spurious "d" in four format
conversions (I put %uld when %ul was sufficient for a plain unsigned long).
Bzzzt, still wrong. The *correct* conversion descriptor for unsigned long
is, and has always been, %lu. %ul expects an unsigned int and appends an
'l' to its value. If it receives an unsigned long, undefined behaviour.


I guess at least technically, I don't need to say "I spoke too soon" :-)
Fortunately , that didn't really break the output, except that there's a
trailing, meaningless 'd' at the end of 4 of the lines. Sorry about that.


It broke everything, due to invoking undefined behaviour, so any output
you got was by accident, rather than by design.
P.S. It took me a while to find a platform that displayed long long values
at all! Good thing I had that Dinkum lib lying around... ;-)


It's been a common Unix extension for ages...


I only use Unix for teaching Unix and making tar files (and for the
latter, Cgwin actually...)
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #22
On 7 Apr 2004 14:09:27 GMT, Da*****@cern.ch (Dan Pop) wrote:
In <r2************ *************** *****@4ax.com> Leor Zolman <le**@bdsoft.co m> writes:
On Wed, 07 Apr 2004 01:13:59 GMT, Leor Zolman <le**@bdsoft.co m> wrote:

Well, that was my very first time attempting to display values of long
longs, and in my confusion I ended up with a spurious "d" in four format
conversions (I put %uld when %ul was sufficient for a plain unsigned long).
Bzzzt, still wrong. The *correct* conversion descriptor for unsigned long
is, and has always been, %lu. %ul expects an unsigned int and appends an
'l' to its value. If it receives an unsigned long, undefined behaviour.


I guess at least technically, I don't need to say "I spoke too soon" :-)
Fortunately , that didn't really break the output, except that there's a
trailing, meaningless 'd' at the end of 4 of the lines. Sorry about that.


It broke everything, due to invoking undefined behaviour, so any output
you got was by accident, rather than by design.
P.S. It took me a while to find a platform that displayed long long values
at all! Good thing I had that Dinkum lib lying around... ;-)


It's been a common Unix extension for ages...


I only use Unix for teaching Unix and making tar files (and for the
latter, Cgwin actually...)
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #23
Leor Zolman wrote:
.... snip ...
I only use Unix for teaching Unix and making tar files (and for
the latter, Cgwin actually...)


Try DJGPP. Much faster. Does all those things.

--
Some useful references:
<http://www.ungerhu.com/jxh/clc.welcome.txt >
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
Nov 14 '05 #24
On Wed, 07 Apr 2004 22:12:53 GMT, CBFalconer <cb********@yah oo.com> wrote:
Leor Zolman wrote:

... snip ...

I only use Unix for teaching Unix and making tar files (and for
the latter, Cgwin actually...)


Try DJGPP. Much faster. Does all those things.


Oh, I have that here. Not sure I ever realized it does C. I got the gcc
version of STLFilt (for C++ of course) supporting djgpp back in 2002...and
I just realized that nowhere in my docs is that fact actually documented.
That's because I just think of djgpp as "yet another gcc clone", and
figured everyone else would probably know that its messages would be the
same as those of "vanilla" gcc. Foo. Thanks for the heads up!
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #25
In <kc************ *************** *****@4ax.com> Leor Zolman <le**@bdsoft.co m> writes:
On 7 Apr 2004 14:09:27 GMT, Da*****@cern.ch (Dan Pop) wrote:
In <r2************ *************** *****@4ax.com> Leor Zolman <le**@bdsoft.co m> writes:
P.S. It took me a while to find a platform that displayed long long values
at all! Good thing I had that Dinkum lib lying around... ;-)


It's been a common Unix extension for ages...


I only use Unix for teaching Unix and making tar files (and for the
latter, Cgwin actually...)

^^^^^^^^^^^^^^
Cygwin's gcc and libraries have supported long long forever, so you had
such a platform right under your nose ;-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
31512
by: Siemel Naran | last post by:
Hi. Is there a way to convert the type signed int to the type unsigned int, char to unsigned char, signed char to unsigned char, and so on for all the fundamental integer types? Something like template <> struct to_unsigned<signed int> : public std::unary_function<signed int, unsigned int> { unsigned int operator()(signed int x) const { return x; } };
14
286
by: amit | last post by:
Hi, What will happen in following scenario.. long a = -2; longlong b = a long c; c = *(ulonglong *)&b; b = c; also when
10
15666
by: tinesan | last post by:
Hello fellow C programmers, I'm just learning to program with C, and I'm wondering what the difference between signed and unsigned char is. To me there seems to be no difference, and the standard doesn't even care what a normal char is (because signed and unsigned have equal behavior). For example if someone does this: unsigned char a = -2; /* or = 254 */
5
6537
by: bruce.james.lee | last post by:
hi i have a problem with integer subtraction in C. printf("%d", c < (a - b)); a is got from a #define and is 0x80000000 and b is got from input and is also 0x80000000. c is ffffffff (-1). Now, this should print 1 (true) but it prints 0!
36
3493
by: felixnielsen | last post by:
What i really wanna do, is defining my own types, it doesnt really matter why. Anyway, i have run into some problems 1) typedef unsigned short U16; U16 test = 0xffffffff; // There should be a limit on this, max value you should be able to asign should be 0xffff // std::cout << test; // result = 0xffff //
10
1863
by: Smurff | last post by:
Hi, This code works fine on win and linux but not on hpux. All is compiled with gcc. Can anyone help please? /*****************************************************************************/ /* */ /* encrypt */
8
2015
by: Charles Sullivan | last post by:
I have a program written in C under Linux (gcc) which a user has ported to run under AT&T SysV R4. He sent me a copy of his makelog which displays a large number of compiler warnings similar to this: warning: semantics of ">>" change in ANSI C; use explicit cast The statement to which this applies is: xuc = ((uc & 0xF0 ) >4);
10
3314
by: =?iso-8859-2?B?SmFuIFJpbmdvuQ==?= | last post by:
Hello everybody, this is my first post to a newsgroup at all. I would like to get some feedback on one proposal I am thinking about: --- begin of proposal --- Proposal to add signed/unsigned modifier to class declarations to next revision of C++ programming language
6
6459
by: Kislay | last post by:
Consider the following code snippet unsigned int i=10; int j= - 2; // minus 2 if(i>j) cout<<"i is greater"; else cout<<"j is greater"; Since i is unsigned , j is greater . I know why , but vaguely . Can
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10465
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.