Thread: RE: [Dev-C++] Unsigned and signed
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2001-10-19 15:08:33
|
<html><div style='background-color:'><DIV> <P>int holds any number from -32,332 to +32,332 (not sure about last 3 digits in each)</P> <P>and an unsigned int holds +64, 664 (again not sure about last 3)<BR><BR></P></DIV> <DIV></DIV> <DIV></DIV>>From: "Ioannis Vranos" <NO...@YA...> <DIV></DIV>>To: "Dev-C++" <DEV...@LI...> <DIV></DIV>>Subject: RE: [Dev-C++] Unsigned and signed <DIV></DIV>>Date: Fri, 19 Oct 2001 17:54:32 +0200 <DIV></DIV>> <DIV></DIV>>signed integer variables can store both positive and negative variables, <DIV></DIV>>unsigned only positive. <DIV></DIV>> <DIV></DIV>>e.g. <DIV></DIV>>int x; <DIV></DIV>>signed int x; // They are both the same <DIV></DIV>> <DIV></DIV>>unsigned int x; <DIV></DIV>> <DIV></DIV>>long y; <DIV></DIV>>signed long y; // They are both the same <DIV></DIV>> <DIV></DIV>>unsigned long y; <DIV></DIV>> <DIV></DIV>> <DIV></DIV>>In the case of int the "int" can be avoided: <DIV></DIV>> <DIV></DIV>>int x; <DIV></DIV>>signed x; // They are both the same <DIV></DIV>> <DIV></DIV>>unsigned x; <DIV></DIV>> <DIV></DIV>> <DIV></DIV>>Also normally we do not use signed but only unsigned when we need so: <DIV></DIV>> <DIV></DIV>>int x; // signed <DIV></DIV>>long y; //signed <DIV></DIV>> <DIV></DIV>>unsigned z; // unsigned int <DIV></DIV>>unsigned long y; <DIV></DIV>>unsigned char c; <DIV></DIV>> <DIV></DIV>>But a char it can be signed or unsigned. It depends from the system. <DIV></DIV>> <DIV></DIV>>E.g. char c; // it can be signed or unsigned <DIV></DIV>> <DIV></DIV>>signed char c; // signed <DIV></DIV>>unsigned char c; // unsigned <DIV></DIV>> <DIV></DIV>> <DIV></DIV>>Ioannis <DIV></DIV>> <DIV></DIV>>* Ioannis Vranos <DIV></DIV>>* Programming pages: http://www.noicys.f2s.com <DIV></DIV>>* Alternative URL: http://run.to/noicys <DIV></DIV>> <DIV></DIV>> <DIV></DIV>> <DIV></DIV>> <DIV></DIV>> > -----Original Message----- <DIV></DIV>> > From: dev...@li... <DIV></DIV>> > [mailto:dev...@li...] On Behalf <DIV></DIV>> > Of mi...@ju... <DIV></DIV>> > Sent: Friday, October 19, 2001 1:36 PM <DIV></DIV>> > To: dev...@li... <DIV></DIV>> > Subject: [Dev-C++] Unsigned and signed <DIV></DIV>> > <DIV></DIV>> > <DIV></DIV>> > What do unsigned and signed do to variables? <DIV></DIV>> > ________________________________________________________________ <DIV></DIV>> > GET INTERNET ACCESS FROM JUNO! <DIV></DIV>> > Juno offers FREE or PREMIUM Internet access for less! <DIV></DIV>> > Join Juno today! For your FREE software, visit: <DIV></DIV>> > http://dl.www.juno.com/get/web/. <DIV></DIV>> > <DIV></DIV>> > <DIV></DIV>> > _______________________________________________ <DIV></DIV>> > Dev-cpp-users mailing list <DIV></DIV>> > Dev...@li... <DIV></DIV>> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users <DIV></DIV>> > <DIV></DIV>> <DIV></DIV>> <DIV></DIV>>_______________________________________________ <DIV></DIV>>Dev-cpp-users mailing list <DIV></DIV>>Dev...@li... <DIV></DIV>>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users <DIV></DIV></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://go.msn.com/bql/hmtag_itl_EN.asp'>http://explorer.msn.com</a><br></html> |
|
From: jansb000 <jan...@wx...> - 2001-10-23 21:00:30
|
Yep, just try this program:
#include <stdio.h>
int main() {
printf("%d", sizeof(int));
}
For a more complete version of this program look at:
http://wcs-jabe.sourceforge.net/source/html/global_8h-source.html
http://wcs-jabe.sourceforge.net/source/html/globmain_8cpp-source.html
This is a program that I wrote to test the size of variables on =
different platforms (C++).
As far as I know an int is always the size that can be handled most =
easily by the CPU but minimal 16 bits. So, on the new Intel processor (I =
believe its the MERCAD) an int may be 64 bits since it is a 64-bit CPU. =
Some super computers also have 64-bit ints.
If you write cross-platform code then you should use 16-bit for integer =
(as an assumption), but you can never count on it that it will occupy =
just 2 bytes of memory.
----- Original Message -----=20
From: Daniel Glenfield=20
To: jan...@wx...=20
Sent: Friday, October 19, 2001 9:06 PM
Subject: Re: [Dev-C++] Unsigned and signed
that's it, knew I had the first 2 numbers right.
so you're telling me that a 32-bit machine can hold even greater =
values for int ? great, that's something my course never told me!
>From: "jansb000"=20
>To: "Daniel Glenfield"=20
>Subject: Re: [Dev-C++] Unsigned and signed=20
>Date: Fri, 19 Oct 2001 21:03:21 +0200=20
>=20
>You mean its -32768 to +32767 for signed and +65535 for unsigned.=20
>However that is only for 16-bit numbers. In DevC++/MingW32 an integer =
is by default 32-bit. On other machines it may be even 64-bit.=20
> ----- Original Message -----=20
> From: Daniel Glenfield=20
> To: dev...@li...=20
> Sent: Friday, October 19, 2001 5:08 PM=20
> Subject: RE: [Dev-C++] Unsigned and signed=20
>=20
>=20
> int holds any number from -32,332 to +32,332 (not sure about last 3 =
digits in each)=20
>=20
> and an unsigned int holds +64, 664 (again not sure about last 3)=20
>=20
>=20
>=20
> >From: "Ioannis Vranos"=20
> >To: "Dev-C++"=20
> >Subject: RE: [Dev-C++] Unsigned and signed=20
> >Date: Fri, 19 Oct 2001 17:54:32 +0200=20
> >=20
> >signed integer variables can store both positive and negative =
variables,=20
> >unsigned only positive.=20
> >=20
> >e.g.=20
> >int x;=20
> >signed int x; // They are both the same=20
> >=20
> >unsigned int x;=20
> >=20
> >long y;=20
> >signed long y; // They are both the same=20
> >=20
> >unsigned long y;=20
> >=20
> >=20
> >In the case of int the "int" can be avoided:=20
> >=20
> >int x;=20
> >signed x; // They are both the same=20
> >=20
> >unsigned x;=20
> >=20
> >=20
> >Also normally we do not use signed but only unsigned when we need =
so:=20
> >=20
> >int x; // signed=20
> >long y; //signed=20
> >=20
> >unsigned z; // unsigned int=20
> >unsigned long y;=20
> >unsigned char c;=20
> >=20
> >But a char it can be signed or unsigned. It depends from the =
system.=20
> >=20
> >E.g. char c; // it can be signed or unsigned=20
> >=20
> >signed char c; // signed=20
> >unsigned char c; // unsigned=20
> >=20
> >=20
> >Ioannis=20
> >=20
> >* Ioannis Vranos=20
> >* Programming pages: http://www.noicys.f2s.com=20
> >* Alternative URL: http://run.to/noicys=20
> >=20
> >=20
> >=20
> >=20
> > > -----Original Message-----=20
> > > From: dev...@li...=20
> > > [mailto:dev...@li...] On Behalf=20
> > > Of mi...@ju...=20
> > > Sent: Friday, October 19, 2001 1:36 PM=20
> > > To: dev...@li...=20
> > > Subject: [Dev-C++] Unsigned and signed=20
> > >=20
> > >=20
> > > What do unsigned and signed do to variables?=20
> > > ________________________________________________________________ =
> > > GET INTERNET ACCESS FROM JUNO!=20
> > > Juno offers FREE or PREMIUM Internet access for less!=20
> > > Join Juno today! For your FREE software, visit:=20
> > > http://dl.www.juno.com/get/web/.=20
> > >=20
> > >=20
> > > _______________________________________________=20
> > > Dev-cpp-users mailing list=20
> > > Dev...@li...=20
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users=20
> > >=20
> >=20
> >=20
> >_______________________________________________=20
> >Dev-cpp-users mailing list=20
> >Dev...@li...=20
> >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users=20
>=20
>=20
=
>------------------------------------------------------------------------=
------=20
> Get your FREE download of MSN Explorer at http://explorer.msn.com=20
> _______________________________________________ Dev-cpp-users =
mailing list Dev...@li... =
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users=20
-------------------------------------------------------------------------=
-----
Get your FREE download of MSN Explorer at http://explorer.msn.com
|