指向指针(一元“和”中的无效左值) [英] pointer-to-pointer (invalid lvalue in unary `&)

查看:98
本文介绍了指向指针(一元“和”中的无效左值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我正在进行的课程做一些Linux内核黑客攻击。

在.c中有一个指向struct(struct example_struct * ex_ptr)的指针

我想在系统调用中访问。我在.c:


extern struct example_struct **指针中定义了指向

指针的指针;


和我试过的代码中的某个地方:


pointer =& ex_ptr;


我在尝试编译内核时遇到此错误:


一元中的左值无效`&''


它指向行:pointer =& ex_ptr; ...任何想法为什么以及什么

i应该做些什么来解决它?

i''m doing some Linux Kernel hacking for a course i''m currently taking.
there is a pointer to a struct (struct example_struct *ex_ptr) in a .c
that i want to access in a system call. i defined a pointer to a
pointer in the .c:

extern struct example_struct **pointer;

and somewhere in the code i tried:

pointer = &ex_ptr;

and i get this error when trying to compile the kernel:

invalid lvalue in unary `&''

and it points to the line: pointer = &ex_ptr;....any idea why and what
i should do to fix it?

推荐答案

2004年4月3日09:49:41 -0800, lm******@eden.rutgers.edu (Lucas Machado)

写道:
On 3 Apr 2004 09:49:41 -0800, lm******@eden.rutgers.edu (Lucas Machado)
wrote:
我正在为我正在进行的课程做一些Linux内核黑客攻击。
有一个指向struct的结构(struct我希望在系统调用中访问的.c
中的example_struct * ex_ptr)。我在.c:

extern struct example_struct **指针中定义了指向
指针的指针;

在我尝试的代码中的某处:

指针=& ex_ptr;

我在尝试编译内核时遇到此错误:

一元&中的无效左值并且它指向行:pointer =& ex_ptr; ....任何想法为什么和什么
我应该做什么来解决它?
i''m doing some Linux Kernel hacking for a course i''m currently taking.
there is a pointer to a struct (struct example_struct *ex_ptr) in a .c
that i want to access in a system call. i defined a pointer to a
pointer in the .c:

extern struct example_struct **pointer;

and somewhere in the code i tried:

pointer = &ex_ptr;

and i get this error when trying to compile the kernel:

invalid lvalue in unary `&''

and it points to the line: pointer = &ex_ptr;....any idea why and what
i should do to fix it?



从你发布的内容来看,一切看起来都很好。你能显示/确切地说/ ex_ptr的

定义是什么样的?无论ex_ptr是什么,似乎没有
有一个与之相关的地址。如果它只是

" pointer'的错误类型,我已经预料到该消息会拼写出来。所以我的猜测是

ex_ptr实际上就像一个常数,就像那个奇怪的那样

听起来......

-leor


-

Leor Zolman --- BD软件--- www.bdsoft.com

C / C ++,Java,Perl和Unix的现场培训

C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html



From what you''ve posted, all looks fine. Can you show /exactly/ what the
definition of ex_ptr looks like? Whatever ex_ptr is, it doesn''t seem to
have an address associated with it. If it were just the wrong type for
"pointer", I''d have expected the message to spell that out. So my guess is
that "ex_ptr" is actually something like a constant, as weird as that
sounds...
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software''s free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html


Lucas Machado写道:
Lucas Machado wrote:
我正在为我正在服用的课程做一些Linux内核黑客攻击。
有一个指向我想在系统调用中访问的.c
中的结构(struct example_struct * ex_ptr)的指针。我在.c:

extern struct example_struct **指针中定义了指向
指针的指针;

在我尝试的代码中的某处:

指针=& ex_ptr;

我在尝试编译内核时遇到此错误:

一元&中的无效左值并且它指向行:pointer =& ex_ptr; ....任何想法为什么和什么
我应该做什么来解决它?
i''m doing some Linux Kernel hacking for a course i''m currently taking.
there is a pointer to a struct (struct example_struct *ex_ptr) in a .c
that i want to access in a system call. i defined a pointer to a
pointer in the .c:

extern struct example_struct **pointer;

and somewhere in the code i tried:

pointer = &ex_ptr;

and i get this error when trying to compile the kernel:

invalid lvalue in unary `&''

and it points to the line: pointer = &ex_ptr;....any idea why and what
i should do to fix it?



你几乎肯定会误诊这个问题。在报告错误的行之前查看

行。简单的事情,比如

错过了'';''之前可能就是这样的罪魁祸首。请注意下面你的作业使用

,这很好。 (如果你的使用不正确'/ b $'''extern'',那么可能会导致链接错误。


#include< stdio .h>


struct example_struct

{

int f;

} basestruct = {0 };

struct example_struct * ex_ptr =& basestruct;


int main(无效)

{

struct example_struct **指针;

指针=& ex_ptr;

(*指针) - > f = 3;

printf(" basestruct.f =%d \ n",basestruct.f);

printf(" ex_ptr-> f =%d \ n",ex_ptr-> f );

printf("(*指针) - > f =%d \ n",(*指针) - > f);

返回0 ;

}

basestruct.f = 3

ex_ptr-> f = 3

(*指针) - > f = 3


You have almost certainly misdiagnosed the problem. Look to the lines
before the one for which the error is reported. Simple things like
missing a '';'' on the line before may be such a culprit. Notice the use
of your assignment below, which is fine. (If you had an incorrect use
of ''extern'', that would probably lead to a linking error instead).

#include <stdio.h>

struct example_struct
{
int f;
} basestruct = { 0};
struct example_struct *ex_ptr = &basestruct;

int main(void)
{
struct example_struct **pointer;
pointer = &ex_ptr;
(*pointer)->f = 3;
printf("basestruct.f = %d\n", basestruct.f);
printf("ex_ptr->f = %d\n", ex_ptr->f);
printf("(*pointer)->f = %d\n", (*pointer)->f);
return 0;
}
basestruct.f = 3
ex_ptr->f = 3
(*pointer)->f = 3


Lucas Machado写道:
Lucas Machado wrote:
我正在做一些Linux内核黑客攻击我目前的课程服用。<无线电通信/>在.c
中有一个指向结构(struct example_struct * ex_ptr)的指针,我想在系统调用中访问它。我在.c:

extern struct example_struct **指针中定义了指向
指针的指针;

在我尝试的代码中的某处:

指针=& ex_ptr;

我在尝试编译内核时遇到此错误:

一元&中的无效左值并且它指向行:pointer =& ex_ptr; ....任何想法为什么和什么
我应该做什么来解决它?
i''m doing some Linux Kernel hacking for a course i''m currently taking.
there is a pointer to a struct (struct example_struct *ex_ptr) in a .c
that i want to access in a system call. i defined a pointer to a
pointer in the .c:

extern struct example_struct **pointer;

and somewhere in the code i tried:

pointer = &ex_ptr;

and i get this error when trying to compile the kernel:

invalid lvalue in unary `&''

and it points to the line: pointer = &ex_ptr;....any idea why and what
i should do to fix it?



你几乎肯定会误诊这个问题。在报告错误的行之前查看

行。简单的事情,比如

错过了'';''之前可能就是这样的罪魁祸首。请注意下面你的作业使用

,这很好。 (如果你的使用不正确'/ b $'''extern'',那么可能会导致链接错误。


#include< stdio .h>


struct example_struct

{

int f;

} basestruct = {0 };

struct example_struct * ex_ptr =& basestruct;


int main(无效)

{

struct example_struct **指针;

指针=& ex_ptr;

(*指针) - > f = 3;

printf(" basestruct.f =%d \ n",basestruct.f);

printf(" ex_ptr-> f =%d \ n",ex_ptr-> f );

printf("(*指针) - > f =%d \ n",(*指针) - > f);

返回0 ;

}

basestruct.f = 3

ex_ptr-> f = 3

(*指针) - > f = 3


You have almost certainly misdiagnosed the problem. Look to the lines
before the one for which the error is reported. Simple things like
missing a '';'' on the line before may be such a culprit. Notice the use
of your assignment below, which is fine. (If you had an incorrect use
of ''extern'', that would probably lead to a linking error instead).

#include <stdio.h>

struct example_struct
{
int f;
} basestruct = { 0};
struct example_struct *ex_ptr = &basestruct;

int main(void)
{
struct example_struct **pointer;
pointer = &ex_ptr;
(*pointer)->f = 3;
printf("basestruct.f = %d\n", basestruct.f);
printf("ex_ptr->f = %d\n", ex_ptr->f);
printf("(*pointer)->f = %d\n", (*pointer)->f);
return 0;
}
basestruct.f = 3
ex_ptr->f = 3
(*pointer)->f = 3


这篇关于指向指针(一元“和”中的无效左值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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