473,594 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
+ 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 1816
pa********@hotm ail.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********@hotm ail.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********@hotm ail.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********@hot mail.com"
<pa********@hot mail.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.l earn.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
8734
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 everything happens at once. Then there must be a bug in time.
125
14652
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
45
3704
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
2026
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 containing pointers into a "flattened" bit stream. Here is my code (it dosen't work). I would be grateful for any feedback that helps fix this. My intention
12
16893
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 there is not a one to one map between a session and a physical TCP connection. A client may disconnect the TCP connection if it is idle for more than 60 seconds... yet a conceptual "session" may last for days at a time. It's necessary that the...
14
24558
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 this, since both are 4 bytes , how can it hold different size? Thank you
31
383
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
5681
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 right thing to use for every var that holds the number of or size in bytes of things. * size_t should only be used when dealing with library functions.
9
1914
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 like this : (very simple..........) 010001010110001101010101010101010101010101 #include<stdio.h>
0
7946
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
8251
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
8372
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
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5408
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();...
0
3859
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2385
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
1
1478
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.