如何在不使用指针的情况下传输地址值 [英] How to transfer an address value without using pointers

查看:55
本文介绍了如何在不使用指针的情况下传输地址值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有以下程序结构:


main

.....

int A = 5;

int * ptr = A; (所以此时ptr存储A的地址)

.....

.....

send_data(... )

....

.....


函数send_data,我需要在它的身上使用地址

A:

void send_data(...){

.....

.....

char * R =(char *)ptr;

......


但是由于编译器的限制(请不要问我为什么:))

我不能在这里使用指针。


目前我还不知道如何发送到函数地址

信息,有人有想法吗?


提前谢谢

Hi,

I have the following program structure:

main
.....
int A=5;
int* ptr= A; (so at this point ptr stores address of A)
.....
.....
send_data(...)
....
.....

for the function send_data, I need on its body to use the address of
A:
void send_data(...){
.....
.....
char* R=(char*) ptr;
......

but due to the limitations of the compiler (please dont ask me why :))
I can not use pointers here.

At the moment I do not know how to send to the function the address
information, somebody has idea ?

Thanks in advance

推荐答案

6月16日晚上10点39分,Horacius ReX< horacius .... @ gmail.comwrote:
On Jun 16, 10:39 pm, Horacius ReX <horacius....@gmail.comwrote:




我有以下程序结构:


main

....

int A = 5;

int * ptr = A; (所以此时ptr存储A的地址)
Hi,

I have the following program structure:

main
....
int A=5;
int* ptr= A; (so at this point ptr stores address of A)



不是你的意思和A?

Don''t you mean &A?


....

....

send_data(...)
....
....
send_data(...)



send_data?

send_data?


...

....


函数send_data,我需要在它的身体上使用地址

A:

void send_data(...){

....

....

char * R =(char *)ptr;

.....


但由于编译器的限制(请不要问我为什么:))

我不能在这里使用指针。
...
....

for the function send_data, I need on its body to use the address of
A:
void send_data(...){
....
....
char* R=(char*) ptr;
.....

but due to the limitations of the compiler (please dont ask me why :))
I can not use pointers here.



为什么?

Why?


目前我不知道如何向函数发送地址

信息,有人有想法吗?
At the moment I do not know how to send to the function the address
information, somebody has idea ?



您可以定义ptr属于全局范围。

You can define ptr to belong to the global scope.


6月16日20:39, Horacius ReX< horacius .... @ gmail.comwrote:
On 16 Jun, 20:39, Horacius ReX <horacius....@gmail.comwrote:

但是由于编译器的限制(请不要问我为什么:))

我不能在这里使用指针。
but due to the limitations of the compiler (please dont ask me why :))
I can not use pointers here.



如果你解释为什么你不能使用

指针,你可能会得到更好的答案。这是编译器的问题还是你的理解

的编译器?

You may well get better answers if you explain why you can''t use
pointers. Is it a problem with the compiler or with your understanding
of the compiler?


Horacius ReX写道:
Horacius ReX wrote:




我有以下程序结构:


main

....

int A = 5;

int * ptr = A; (所以此时ptr存储地址为A)
Hi,

I have the following program structure:

main
....
int A=5;
int* ptr= A; (so at this point ptr stores address of A)



编号你想:


int * ptr =& A;

No. You want:

int *ptr = &A;


....

....

send_data(...)

...

....


函数send_data,我需要在它的主体上使用
A:

void send_data(...){

....

....

char * R =(char *)ptr;

.....
....
....
send_data(...)
...
....

for the function send_data, I need on its body to use the address of
A:
void send_data(...){
....
....
char* R=(char*) ptr;
.....



这指定给R通过将

ptr的内容解释为char *值得出的值。

This assigns to R the value derived from interpreting the contents of
ptr as a char * value.


但由于编译器的限制(请不要问我为什么:))

我不能在这里使用指针。


目前我不知道如何向函数发送地址

信息,有人有想法吗?


提前付款
but due to the limitations of the compiler (please dont ask me why :))
I can not use pointers here.

At the moment I do not know how to send to the function the address
information, somebody has idea ?

Thanks in advance



如果你的系统有限,那么你可能tr y将地址存储在

中一个适当的整数对象。如果你的系统有他们使用intptr_t或

uintptr_t。

If your system is this limited then you might try storing the address in
a appropriate integer object. If your system has them use intptr_t or
uintptr_t.


这篇关于如何在不使用指针的情况下传输地址值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆