* Pointer to int
@ 2004-07-21 21:11 Ronaldo Zacarias Afonso
2004-07-21 23:14 ` Luiz Fernando N. Capitulino
2004-07-22 5:21 ` canbaby
0 siblings, 2 replies; 3+ messages in thread
From: Ronaldo Zacarias Afonso @ 2004-07-21 21:11 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Mail message body --]
[-- Type: text/plain, Size: 718 bytes --]
Hello everybody,
I'm iniciating in the C programming language and there are some things
that I realy need to understand, so the question is:
In the code:
int i;
struct some_struct *ptr;
ptr = &some_other_struct;
i = (int) ptr;
1) Is the last sentence a valid one?
2) If it is, what is realy happening?
note - It seems very stranger to me. A struct pointer being "transformed"
into a int variable.
Thanks.
_________________________________________________________________________________
Quer mais velocidade?
Só com o acesso Aditivado iG, a velocidade que você quer na hora que você precisa.
Clique aqui: http://www.acessoaditivado.ig.com.br
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Pointer to int
2004-07-21 21:11 Pointer to int Ronaldo Zacarias Afonso
@ 2004-07-21 23:14 ` Luiz Fernando N. Capitulino
2004-07-22 5:21 ` canbaby
1 sibling, 0 replies; 3+ messages in thread
From: Luiz Fernando N. Capitulino @ 2004-07-21 23:14 UTC (permalink / raw)
To: Ronaldo Zacarias Afonso; +Cc: linux-c-programming
Hi Ronaldo,
Em Wed, 21 Jul 2004 18:11:29 -0300
Ronaldo Zacarias Afonso <r_zaca@ig.com.br> screveu:
| I'm iniciating in the C programming language and there are some things
| that I realy need to understand, so the question is:
|
| In the code:
|
| int i;
| struct some_struct *ptr;
|
| ptr = &some_other_struct;
|
| i = (int) ptr;
|
|
| 1) Is the last sentence a valid one?
Yes, but depending on the architecture the int variable will not be enough.
| 2) If it is, what is realy happening?
|
| note - It seems very stranger to me. A struct pointer being "transformed"
| into a int variable.
Variables address are also numbers, so you can handle it with int variables.
The two most important questions here are: 1) you need to _know_ exactly what
you are doing, and 2) the variable size.
For i386 architecture, you will need a 32-bit variable to store an address, so
for you example "unsigned int" is what we want (assuming you want all the address,
maybe you want a half of it, or something like that).
And do a +1 in a pointer is not the something to do a +1 in the `i' above.
--
Luiz Fernando
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Pointer to int
2004-07-21 21:11 Pointer to int Ronaldo Zacarias Afonso
2004-07-21 23:14 ` Luiz Fernando N. Capitulino
@ 2004-07-22 5:21 ` canbaby
1 sibling, 0 replies; 3+ messages in thread
From: canbaby @ 2004-07-22 5:21 UTC (permalink / raw)
To: Ronaldo Zacarias Afonso; +Cc: linux-c-programming
Ronaldo Zacarias Afonso wrote:
> Hello everybody,
>
> I'm iniciating in the C programming language and there are some things
>that I realy need to understand, so the question is:
>
> In the code:
>
> int i;
> struct some_struct *ptr;
>
> ptr = &some_other_struct;
>
> i = (int) ptr;
>
>
> 1) Is the last sentence a valid one?
> 2) If it is, what is realy happening?
>
>note - It seems very stranger to me. A struct pointer being "transformed"
>into a int variable.
>
> Thanks.
>
>
>_________________________________________________________________________________
>Quer mais velocidade?
>Só com o acesso Aditivado iG, a velocidade que você quer na hora que você precisa.
>Clique aqui: http://www.acessoaditivado.ig.com.br
>
>
>
yes,it's a validate one.
now the var i have the the some_other_struct address value,you could
reconstruct the struct like this:
struct some_struct *newstruct = (struct some_struct *)i;
then freely use the newstruct.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-07-22 5:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-21 21:11 Pointer to int Ronaldo Zacarias Afonso
2004-07-21 23:14 ` Luiz Fernando N. Capitulino
2004-07-22 5:21 ` canbaby
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).