473,474 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What is the need for long when int and long are both 4 bytes

hi All
I understand the need for long long , but what is the purpose of long
as a data type separately. Just makes the language intimidating to
start with, when you have to deal with so many data types.

Nov 3 '07 #1
4 1800
pa********@hotmail.com wrote:
Re: What is the need for long when int and long are both 4 bytes
Where did you get that idea? Neither are required to be 4 bytes, and they
are not required to span the same range. The requirements are:

int can represent all integers in the interval [INT_MIN, INT_MAX].

long can represent all integers in the interval [LONG_MIN, LONG_MAX].

Moreover, we have the following guarantees inherited from C:

INT_MIN <= -32767
INT_MAX >= 32767

LONG_MIN <= -2147483647
LONG_MAX >= 2147483647

hi All
I understand the need for long long , but what is the purpose of long
as a data type separately. Just makes the language intimidating to
start with, when you have to deal with so many data types.
The requirements for the type int are somewhat special. If you look at
short, long, long long, you will find that they more or less match your
expectations. However, the idea behind int is that it should be
the "natural" arithmetic type of the machine (i.e., it should be
represented by one word). Now, what that means is a little iffy, e.g., do
you think of processor registers or of memory and bus architecture; but
that was the idea: in the word of the standard [3.9.1/2]:

... Plain ints have the natural size suggested by the architecture of the
execution environment [39]; the other signed integer types are provided to
meet special needs.

[39]= that is, large enough to contain any value in the range of INT_MIN
and INT_MAX, as defined in the header <climits>.
Best

Kai-Uwe Bux
Nov 3 '07 #2
pa********@hotmail.com wrote:
hi All
I understand the need for long long , but what is the purpose of long
as a data type separately. Just makes the language intimidating to
start with, when you have to deal with so many data types.
Have you ever considered an 8 or 16 bit processor where int is 16 bits?
Or a 64 bit machine where int is 32 bits?

--
Ian Collins.
Nov 3 '07 #3
pa********@hotmail.com wrote:
hi All
I understand the need for long long ,
.... which doesn't exist in standard C++ ...
but what is the purpose of long as a data type separately.
You need it if you want to be sure to get a type that has at least 32
siginificant bits. int doesn't give you that guarantee.

Nov 3 '07 #4
On 3 Nov 2007 01:14:31 -0700, "pa********@hotmail.com"
<pa********@hotmail.comwrote in comp.lang.c++:
hi All
I understand the need for long long , but what is the purpose of long
as a data type separately. Just makes the language intimidating to
start with, when you have to deal with so many data types.
That's funny, I use an implementation where sizeof(int) is 1 and
sizeof(long) is 2. Are you sure your compiler isn't broken?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Nov 5 '07 #5

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

Similar topics

12
by: Henning | last post by:
Hi grp! Trying to receive a udp msg in vb6, but it shows only zeros. What have I missed? /Henning -- Time is present only to prevent everything from happening at once. Still it seems that...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
45
by: Curt Geske | last post by:
I'm suprised no one suggested a union! #include <stdio.h> union _x { long lng; char byt; } X; void main( void )
11
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
12
by: David Sworder | last post by:
Hi, I'm writing an application in which a client (C#/WinForms) and server (C#/service) interact with one another. The client establishes a "session" with the server but for scalability reasons...
14
by: Imran | last post by:
hello all I am bit confused with int and long data type. I read in some book that, int cal hold 2^16 values where in long can hold 2^32. and both data types are 4 bytes long. My doubt...
31
by: Cesar Rodas | last post by:
Hello to all As far I know the unsigned char just use 1-byte, long 4-bytes... is this right??? Well I have the next code... #include <stdio.h> #include <stdlib.h>
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
9
by: xiao | last post by:
It always dumped when I tried to run it... But it compiles OK. What I want to do is to do a test: Read information from a .dat file and then write it to another file. The original DAT file is...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.