473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

address change

Hi all,

consider this,

int x=19;
now &x = 1789; /*this is illegal in c*/

now my question is is there a round about way to do this in
C....??????
Dec 3 '07 #1
9 1446
On Dec 3, 5:16 pm, aark...@gmail.com wrote:
Hi all,

consider this,

int x=19;
now &x = 1789; /*this is illegal in c*/
Certainly is.
now my question is is there a round about way to do this in
C....??????
Do what? You can't change the lvalue of an object.
Dec 3 '07 #2
aa*****@gmail.com wrote:
Hi all,

consider this,

int x=19;
now &x = 1789; /*this is illegal in c*/

now my question is is there a round about way to do this in
C....??????
What are you trying to do? And why?

Variables cannot be re-seated. A variable ties a name to a location. If
you wish to do something like this, you may need a pointer type:

int a=19;
int b=94;

int *x=&a;
/* now *x is the same as a */

x = &b;
/* now *x is the same as b */

Memory addresses cannot be directly entered into portable C code.
Integers cannot be converted to pointer types [1]. Your implementation
may provide a way of doing this, but it is not universal. Why do you
want to do this?

Philip

[1] with the two exceptions of 0, which needn't be converted to memory
address 0 at all, and the value of an intptr_t that was previously
generated from a pointer type.
Dec 3 '07 #3
aa*****@gmail.com wrote:
Hi all,

consider this,

int x=19;
now &x = 1789; /*this is illegal in c*/

now my question is is there a round about way to do this in
C....??????
(a) No.

(b) No, not even if you replace the integer `1789` with an address.

(c) Why do you want to do this?

(d) For some answers to (c), you may be able to imitate what you want
by judicious use of pointers; `x` would likely become a pointer-to-int,
you'd use `*x` not `x` mostly, and then your assignment would be
`x = newAddress`. But only for /some/ answers to (c).

(e) There is no (e).

--
Christophr "Jams" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Dec 3 '07 #4
On Dec 3, 8:28 pm, Philip Potter <p...@doc.ic.ac.ukwrote:
aark...@gmail.com wrote:
Hi all,
consider this,
int x=19;
now &x = 1789; /*this is illegal in c*/
now my question is is there a round about way to do this in
C....??????

What are you trying to do? And why?
just experimenting with things, to learn more about c
[1] with the two exceptions of 0, which needn't be converted to memory
address 0 at all, and the value of an intptr_t that was previously
generated from a pointer type.
what does intptr_t mean???
what is it's purpose ???
is it defined in stddef.h ????

i have seen ptrdiff_t but not this one
Dec 3 '07 #5
aa*****@gmail.com wrote:
On Dec 3, 8:28 pm, Philip Potter <p...@doc.ic.ac.ukwrote:
>aark...@gmail.com wrote:
>>Hi all,
consider this,
int x=19;
now &x = 1789; /*this is illegal in c*/
now my question is is there a round about way to do this in
C....??????
What are you trying to do? And why?

just experimenting with things, to learn more about c
Always a commendable goal.
>[1] with the two exceptions of 0, which needn't be converted to memory
address 0 at all, and the value of an intptr_t that was previously
generated from a pointer type.

what does intptr_t mean???
what is it's purpose ???
is it defined in stddef.h ????
It's not directly related to the problem at hand; I mentioned it as an
exception to the general rule I stated.

intptr_t is a C99 integer type which is enables you to convert pointers
to integers and back again. I have never used it, and I have never seen
it used, though I'm sure it has been somewhere. It is an optional type,
so portable code won't rely on it.
Dec 3 '07 #6
aa*****@gmail.com wrote:
On Dec 3, 8:28 pm, Philip Potter <p...@doc.ic.ac.ukwrote:
>aark...@gmail.com wrote:
Hi all,
consider this,
int x=19;
now &x = 1789; /*this is illegal in c*/
now my question is is there a round about way to do this in
C....??????

What are you trying to do? And why?

just experimenting with things, to learn more about c
>[1] with the two exceptions of 0, which needn't be converted to
[memory
address 0 at all, and the value of an intptr_t that was previously
generated from a pointer type.

what does intptr_t mean???
what is it's purpose ???
is it defined in stddef.h ????
It is defined in stdint.h and thus is C99 specific.
Roughly speaking any pointer to void can be converted to intptr_t or
uintptr_t and when converted back to a pointer to void, will compare
equal to the original pointer.

See section 7.18.1.4 of n1256.

Dec 3 '07 #7
Philip Potter <pg*@doc.ic.ac.ukwrites:
[...]
Memory addresses cannot be directly entered into portable C
code. Integers cannot be converted to pointer types [1]. Your
implementation may provide a way of doing this, but it is not
universal. Why do you want to do this?

[1] with the two exceptions of 0, which needn't be converted to memory
address 0 at all, and the value of an intptr_t that was previously
generated from a pointer type.
Correction: integers can always be converted to pointer types (in most
cases, this requires an explicit cast). The result of such a
conversion is guaranteed to be meaningful only in the cases you
mention; in other cases, the result is implementation-defined, and may
invoke undefined behavior (for example, if the resulting pointer is
not correctly aligned).

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 3 '07 #8
santosh wrote:
aa*****@gmail.com wrote:
>Philip Potter <p...@doc.ic.ac.ukwrote:
>>aark...@gmail.com wrote:

consider this,

int x=19;
now &x = 1789; /*this is illegal in c*/

now my question is is there a round about way to do this in
C....??????

What are you trying to do? And why?

just experimenting with things, to learn more about c
>>[1] with the two exceptions of 0, which needn't be converted to
[memory address 0 at all, and the value of an intptr_t that was
previously generated from a pointer type.

what does intptr_t mean???
what is it's purpose ??? is it defined in stddef.h ????

It is defined in stdint.h and thus is C99 specific.
Roughly speaking any pointer to void can be converted to intptr_t
or uintptr_t and when converted back to a pointer to void, will
compare equal to the original pointer.

See section 7.18.1.4 of n1256.
Note the last sentence of the following quote:

7.18.1.4 Integer types capable of holding object pointers

[#1] The following type designates a signed integer type
with the property that any valid pointer to void can be
converted to this type, then converted back to pointer to
void, and the result will compare equal to the original
pointer:

intptr_t

The following type designates an unsigned integer type with
the property that any valid pointer to void can be converted
to this type, then converted back to pointer to void, and
the result will compare equal to the original pointer:

uintptr_t

These types are optional.

i.e. they may not exist at all.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 3 '07 #9
ais523 <ai****@bham.ac.ukwrites:
Your line

int x=19;

is equivalent to

auto int x=19; /* nobody ever uses auto because it's everywhere either
forbidden or default */

which tells the compiler to find storage for x that lasts until it
goes out of scope;
At the risk of seeming overly picky I'd point out that the link
between lifetime and cope is more subtle than that. The lifetime of
an automatic variable[1] extends from the time when execution enters
the block with which it is associated to the time when execution of
the block ends. Calling a function will, in the terminology of the
standard, suspend the execution of the block -- the names of the
automatic variables go out of scope but the variables continue to
exist.

To further illustrate the messy link, the exact (and seemingly
deliberate) wording makes the following program well-defined and
makes it print 42:

#include <stdio.h>

int main(void)
{
int *ip = 0;
start:
if (ip) {
printf("%d\n", *ip);
return 0;
}
int i = 42;
ip = &i;
goto start;
}

The variable 'i' is accessed (via a pointer) in a part of the block
where the name 'i' is not in scope but the lifetime of the variable
must exist from the time execution enters the block of main.

[1] that does not have variable length array type.

--
Ben.
Dec 5 '07 #10

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

Similar topics

0
by: Dr. StrangeDub | last post by:
I'm looking for an API to change the IP address of a non-networked PC. Specifically, my program must change the Host ID (aka Host address) portion of the IP address. This is for a factory utility...
8
by: YAN | last post by:
Hi, I want to get the mac address from a machine, which i have the IP address of that machine, how can i do that? I know how to get the mac address of the local machine from the following code: ...
3
by: Bernd Giegerich | last post by:
Hi, we had a strange problem with DB2 8.2 Enterprise Edition on Windows 2003 (Standard) Server. We installed DB2 8.2 (8.1.7) directly on a naked W2K3 system (no migration, no update -> no...
3
by: roger beniot | last post by:
I would like to figure out how to detect an IP address change for an XP/Win2K3 machine that is leasing an IP via DHCP (and do it in C#)... Is there any event that indicates an IP address...
2
by: A.M | last post by:
Hi, I had a web server contained a web service. We had to change the web server computer; so all client proxies must point to new web server. My understanding is we have to compile all...
5
by: olduncleamos | last post by:
Hi all. Is there any legitimate reason the IP address from a client will change between request? I am wondering if I can autheticate a session by making sure they all come from the same IP. I...
4
by: usenet | last post by:
Hello, I am running my code on an embedded platform without OS. I have defined some data in a section called .eeprom. The section is defined by the linker script and starts at address zero. The...
4
by: andreas.w.h.k. :-\) | last post by:
How do I change the address location in the wsdl <wsdl:port name="SearchSoap12" binding="tns:SearchSoap12"> <soap12:address location="http://searchservices/engine/search.asmx" /> </wsdl:port> ...
3
by: Newish | last post by:
Hi Regarding DLL base address: 1) What does it mean? 2) Should it ever be changed? 3) What are the rules to change it?
10
by: skyy | last post by:
Hi.. I am working on a CGI script to enable client to obtain the server ip address and then change to the IP address it prefer. The server IP address can be obtain from the environment variable...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.