473,756 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

addresses and integers

I've read in the standard that addresses
basically can't be interpreted as integers.
If they can, it is implementation defined
behavior. However, if they can't be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?
Nov 14 '05 #1
87 3350
j0mbolar wrote:

I've read in the standard that addresses
basically can't be interpreted as integers.
If they can, it is implementation defined
behavior. However, if they can't be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?


Bases and offsets.

--
pete
Nov 14 '05 #2
On Mon, 30 Aug 2004 00:21:31 GMT, pete <pf*****@mindsp ring.com> wrote
in comp.lang.c:
j0mbolar wrote:

I've read in the standard that addresses
basically can't be interpreted as integers.
If they can, it is implementation defined
behavior. However, if they can't be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?


Bases and offsets.


Can you provide any justification at all for your apparently
ridiculous assertion?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #3
On 29 Aug 2004 16:57:46 -0700, j0******@engine er.com (j0mbolar) wrote
in comp.lang.c:
I've read in the standard that addresses
basically can't be interpreted as integers.
That's right, addresses are constants. In fact, they are rvalues, not
lvalues. Functions can't be interpreted as integers either, nor can
structures. What of it?
If they can, it is implementation defined
behavior. However, if they can't be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?


Addresses in C are not "composed" of anything. They have no defined
inner structure, just as the floating point types do not.

There is a requirement that an address can be represented in a string
of binary digits, because an address can be stored in a pointer object
of appropriate type, that pointer object can be inspected as an array
of unsigned chars, and upon such inspection the pointer object must
contain bits and nothing but bits.

This same possibility of inspection as the bits contained in an array
of unsigned characters also applies to the floating point types, but
the interpretation or meaning of those bits is totally unspecified by
the standard.

The standard does require that if an implementation provides an
integer type wide enough to contain a pointer, assignment with a cast
of a pointer value to that integer type and back again with a cast to
the original pointer type will yield an identical pointer. C99 even
defines typedef to be used for such a type, intptr_t and uintptr_t,
although they are optional. I think it would have been preferable for
the standard require the typedefs if such an integer type existed, the
way it requires the exact width definitions.

The standard does not require or guarantee that you can do anything
useful with a converted pointer in such a type, other than converting
it back. In particular, there is no guarantee that:

char name [] = "name";
char *n = name;
uintptr_t up = n;
++up;
n = up;

....n now points to the 'a' in name, or has any valid value at all.

Addresses have absolutely no portability at all, even between
executions of the same program.

What portability do you think they should have, and why? And why do
you think you need to think of them or treat them as integers? What
is it that you think you need to do with addresses that cannot
legitimately be done with pointers?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #4
In article <nr************ *************** *****@4ax.com>,
Jack Klein <ja*******@spam cop.net> wrote:
On Mon, 30 Aug 2004 00:21:31 GMT, pete <pf*****@mindsp ring.com> wrote
in comp.lang.c:
j0mbolar wrote:

I've read in the standard that addresses
basically can't be interpreted as integers.
If they can, it is implementation defined
behavior. However, if they can't be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?


Bases and offsets.


Can you provide any justification at all for your apparently
ridiculous assertion?


That's how C pointers were implemented on Symbolics Lisp Machines.
That's also a non-ridiculous way to implement them on a CPU that has a
reasonable segmented architecture (as opposed to the hoops you have to
jump through to use x86's segmentation).

--
Barry Margolin, ba****@alum.mit .edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Nov 14 '05 #5
Jack Klein <ja*******@spam cop.net> writes:
On Mon, 30 Aug 2004 00:21:31 GMT, pete <pf*****@mindsp ring.com> wrote
in comp.lang.c:
j0mbolar wrote:
>
> I've read in the standard that addresses
> basically can't be interpreted as integers.
> If they can, it is implementation defined
> behavior. However, if they can't be viewed
> as integers in any sense as far as portability
> goes, what then, should one think of addresses
> being composed of?


Bases and offsets.


Can you provide any justification at all for your apparently
ridiculous assertion?


It's not too unreasonable if the "base" is the beginning of an
array and the "offset" is the number of elements from the base.
That's my mental model for abstract C arrays, anyway. It also
works for individual objects not within an array, which can be
treated with 1 element. It does break down when you're dealing
with e.g. structure members though.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #6
On Sun, 29 Aug 2004 19:07:12 -0700 in comp.std.c, Ben Pfaff
<bl*@cs.stanfor d.edu> wrote:
Jack Klein <ja*******@spam cop.net> writes:
On Mon, 30 Aug 2004 00:21:31 GMT, pete <pf*****@mindsp ring.com> wrote
in comp.lang.c:
j0mbolar wrote:
>
> I've read in the standard that addresses
> basically can't be interpreted as integers.
> If they can, it is implementation defined
> behavior. However, if they can't be viewed
> as integers in any sense as far as portability
> goes, what then, should one think of addresses
> being composed of?

Bases and offsets.


Can you provide any justification at all for your apparently
ridiculous assertion?


It's not too unreasonable if the "base" is the beginning of an
array and the "offset" is the number of elements from the base.
That's my mental model for abstract C arrays, anyway. It also
works for individual objects not within an array, which can be
treated with 1 element. It does break down when you're dealing
with e.g. structure members though.


Nor really, the assertion still holds, structure member offsets are
then in addressing units (instead of number of elements) from the
structure base.

--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada

Br**********@CS i.com (Brian[dot]Inglis{at}Syste maticSW[dot]ab[dot]ca)
fake address use address above to reply
Nov 14 '05 #7
Jack Klein wrote:

On Mon, 30 Aug 2004 00:21:31 GMT, pete <pf*****@mindsp ring.com> wrote
in comp.lang.c:
j0mbolar wrote:

I've read in the standard that addresses
basically can't be interpreted as integers.
If they can, it is implementation defined
behavior. However, if they can't be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?


Bases and offsets.


Can you provide any justification at all for your apparently
ridiculous assertion?


It's the way that pointers (addresses) relate to
each other with arithmetic and relational operators.
You can't add two pointers together,
because pointer types are not arithmetic types.
Relational operations for pointers, are only defined
for pointers which are offset from a common base.

The address of the lowest addressable byte of an object is
(char *)&object
and the address of the highest is
(char *)&object + sizeof object - 1

That's how I think of pointers.

--
pete
Nov 14 '05 #8
j0mbolar wrote:
I've read in the standard that addresses
You probably mean pointers.
basically can't be interpreted as integers.
If they can, it is implementation defined behavior.
All that means is that the ANSI/ISO C standards
do not define any relationship between integers and pointers.
However, if they can't be viewed as integers
in any sense as far as portability goes,
As far as portability goes,
you can almost always count on the fact that
pointers have the same representation as an unsigned int --
a machine word. There are practically *no* exceptions
to this rule for most C programmers.
what, then, should one think of addresses being composed of?


A pointer is an object which may contain values
which are the addresses of valid objects.
Nov 14 '05 #9
j0mbolar wrote:
I've read in the standard that addresses
basically can't be interpreted as integers.
If they can, it is implementation defined
behavior. However, if they can't be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?


Think of them as consisting of (segment,offset )
pairs. Why do you care, so long as they work?

Nov 14 '05 #10

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

Similar topics

14
5491
by: pras.vaidya | last post by:
hi, please help me with this problem : - how to swap two addresses .For eg variable i is located at 2000 and j at 3000 . Now i call swap function . Result should be that i should be now having address 3000 and j should be having 2000. Is it the normal swapping of two number ? if no please help me out. Thanks in advance
13
17186
by: In a little while | last post by:
thanks
0
9271
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
10031
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
9869
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
9838
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
8709
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
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
5140
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...
1
3805
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
3354
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.