Thread: [Dev-C++] int and long int sizes
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <and...@su...> - 2003-09-01 03:13:16
|
Dear Users,
printf("%d\n", sizeof(long int));
and
printf("%d\n", sizeof(int));
produces the same value, 4.
Is there no more difference between a int and a long int?
Regards
Andre Barros
|
|
From: <and...@su...> - 2003-09-01 03:14:34
|
I forgot to tell: Windows XP platform
-----Mensagem original-----
De: André Macário Barros [mailto:and...@su...]
Enviada em: segunda-feira, 1 de setembro de 2003 00:13
Para: Dev-Cpp-Users
Assunto: int and long int sizes
Dear Users,
printf("%d\n", sizeof(long int));
and
printf("%d\n", sizeof(int));
produces the same value, 4.
Is there no more difference between a int and a long int?
Regards
Andre Barros
|
|
From: Michael D. S. <for...@hi...> - 2003-09-01 06:53:43
|
You will notice that everything below is qualified with "probably" or "I=20
believe." An electrical engineer I Am Not, but...
Probably not. Much of this, "save a byte" architecture originated when=20
computers had thousands rather than millions, and now billions of memory=20
positions. I believe it had to do with the fact that the math processor=20
required that numbers be aligned on "word" (4 byte) or "double word" (8=20
byte) boundaries.
For instance, if you had an "a" in memory (position 1) and then a number,=20
if the number was a word boundary, it started in position 4, double word=20
boundary position 8, resulting in 3 in the first case and 7 in the second=20
case skipped (wasted) memory positions. With only a few thousand memory=20
positions thinking about this and packing things in so that as little=20
memory as possible was unused was important.
At least, I think a word was 4 and double word was 8 -- maybe even half=20
word math could be done in assembler -- it's been 35 years and I'm getting=
=20
Alzheimers -- lighten up :)
With 32 bit architecture, everything is aligned on a word boundary and XP=20
is probably 64 bit (double word) architecture. That means that saving=20
(attempting to save) a byte in memory by specifically programming a number=
=20
you know is going to be very small, differently than one you know is going=
=20
to be larger has no meaning any more. Unless of course you have a really=20
large number and you need to specify something like a double double word.
But, at each point in time backwards compatibility was needed so that all=20
the programs that were already written didn't have to be rewritten -- that=
=20
would never be a "feature" for anything new -- so we're still stuck with=20
some of these "ancient" (in computer terms, you know) concepts.
Or something like that -- or maybe you did that wrong :)
ms
At 10:14 PM 8/31/03, you wrote:
>I forgot to tell: Windows XP platform
>
>-----Mensagem original-----
>De: Andr=E9 Mac=E1rio Barros [mailto:and...@su...]
>Enviada em: segunda-feira, 1 de setembro de 2003 00:13
>Para: Dev-Cpp-Users
>Assunto: int and long int sizes
>
>
>Dear Users,
>
> printf("%d\n", sizeof(long int));
>and
> printf("%d\n", sizeof(int));
>
>produces the same value, 4.
>
>Is there no more difference between a int and a long int?
>
>Regards
>Andre Barros
>
>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Per W. <pw...@ia...> - 2003-09-01 05:01:54
|
short <=3D int <=3D long.
In this case short=3D2, int=3Dlong=3D4, which is quite common for a 32-bit
platform. On 16-bit platforms it was normally: short=3Dint=3D2, long=3D4.
/Per W
On Mon, 1 Sep 2003, Andr=E9 Mac=E1rio Barros wrote:
> Dear Users,
>
> printf("%d\n", sizeof(long int));
> and
> printf("%d\n", sizeof(int));
>
> produces the same value, 4.
>
> Is there no more difference between a int and a long int?
>
> Regards
> Andre Barros
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: <and...@su...> - 2003-09-01 10:02:02
|
Thanks Mr PW,
:-) Andre
-----Mensagem original-----
De: Per Westermark [mailto:pw...@ia...]
Enviada em: segunda-feira, 1 de setembro de 2003 02:01
Para: André Macário Barros
Cc: Dev-Cpp-Users
Assunto: Re: [Dev-C++] int and long int sizes
short <= int <= long.
In this case short=2, int=long=4, which is quite common for a 32-bit
platform. On 16-bit platforms it was normally: short=int=2, long=4.
/Per W
On Mon, 1 Sep 2003, André Macário Barros wrote:
> Dear Users,
>
> printf("%d\n", sizeof(long int));
> and
> printf("%d\n", sizeof(int));
>
> produces the same value, 4.
>
> Is there no more difference between a int and a long int?
>
> Regards
> Andre Barros
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Ioannis V. <iv...@em...> - 2003-09-01 09:20:08
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Andr? Macario Barros
> Sent: Monday, September 01, 2003 6:13 AM
> To: Dev-Cpp-Users
> Subject: [Dev-C++] int and long int sizes
>
>
> Dear Users,
>
> printf("%d\n", sizeof(long int));
> and
> printf("%d\n", sizeof(int));
>
> produces the same value, 4.
>
> Is there no more difference between a int and a long int?
C & C++ standards do not require the types to be different. The size of a
type is implementation dependent. The only restriction that exists is that
sizeof(char)==sizeof(signed char)==sizeof(unsigned char)==1 byte.
So in theory an implementation is allowed to have sizeof(long)=1.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|