473,669 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pointer-to-pointer (invalid lvalue in unary `&)

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?
Nov 14 '05 #1
19 3842
On 3 Apr 2004 09:49:41 -0800, lm******@eden.r utgers.edu (Lucas Machado)
wrote:
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?


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
Nov 14 '05 #2
Lucas Machado wrote:
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?

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("basestr uct.f = %d\n", basestruct.f);
printf("ex_ptr->f = %d\n", ex_ptr->f);
printf("(*point er)->f = %d\n", (*pointer)->f);
return 0;
}
basestruct.f = 3
ex_ptr->f = 3
(*pointer)->f = 3
Nov 14 '05 #3
Lucas Machado wrote:
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?

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("basestr uct.f = %d\n", basestruct.f);
printf("ex_ptr->f = %d\n", ex_ptr->f);
printf("(*point er)->f = %d\n", (*pointer)->f);
return 0;
}
basestruct.f = 3
ex_ptr->f = 3
(*pointer)->f = 3
Nov 14 '05 #4
"Leor Zolman" <le**@bdsoft.co m> wrote in message
news:re******** *************** *********@4ax.c om...
On 3 Apr 2004 09:49:41 -0800, lm******@eden.r utgers.edu (Lucas Machado)
wrote:
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?


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


Ditto! How is ex_ptr defined?

Should be something like:
struct example_struct ex_st;
struct example_struct *ex_ptr;
struct example_struct **pointer;

If you simply want the problem to go away to see if it is a compiler error,
try casting it. That would hide any errors that might occur due to the
compiler only... changing your debugging process from finding a syntax error
to figuring out why your computer is crashing :)

pointer = (struct example_struct **pointer)&ex_p tr;

Nov 14 '05 #5
"Leor Zolman" <le**@bdsoft.co m> wrote in message
news:re******** *************** *********@4ax.c om...
On 3 Apr 2004 09:49:41 -0800, lm******@eden.r utgers.edu (Lucas Machado)
wrote:
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?


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


Ditto! How is ex_ptr defined?

Should be something like:
struct example_struct ex_st;
struct example_struct *ex_ptr;
struct example_struct **pointer;

If you simply want the problem to go away to see if it is a compiler error,
try casting it. That would hide any errors that might occur due to the
compiler only... changing your debugging process from finding a syntax error
to figuring out why your computer is crashing :)

pointer = (struct example_struct **pointer)&ex_p tr;

Nov 14 '05 #6
Chris Fogelklou wrote:

<snip>
If you simply want the problem to go away to see if it is a compiler
error,
try casting it.
That doesn't seem very fruitful advice. He'd be better off trying to
understand the type system than trying to learn how to circumvent it.
That would hide any errors that might occur due to the
compiler only... changing your debugging process from finding a syntax
error to figuring out why your computer is crashing :)
Finding the syntax error is much easier.
pointer = (struct example_struct **pointer)&ex_p tr;


That cast is badly-formed, and requires a diagnostic.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #7
Chris Fogelklou wrote:

<snip>
If you simply want the problem to go away to see if it is a compiler
error,
try casting it.
That doesn't seem very fruitful advice. He'd be better off trying to
understand the type system than trying to learn how to circumvent it.
That would hide any errors that might occur due to the
compiler only... changing your debugging process from finding a syntax
error to figuring out why your computer is crashing :)
Finding the syntax error is much easier.
pointer = (struct example_struct **pointer)&ex_p tr;


That cast is badly-formed, and requires a diagnostic.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #8
> That doesn't seem very fruitful advice. He'd be better off trying to
understand the type system than trying to learn how to circumvent it.

Yep.
changing your debugging process from finding a syntax
error to figuring out why your computer is crashing :)


Finding the syntax error is much easier


Hence the smiley and the statement that he would have to figure out why the
computer is crashing (sarcasm... oops... my bad :)
pointer = (struct example_struct **pointer)&ex_p tr;


That cast is badly-formed, and requires a diagnostic.


Hmm... It compiles on my system... but from the other posts/responses I've
been participating in, I think my system might be broken. Could you please
elaborate?

typedef struct ui_tag {
uint16 i;
uint16 j;
uint16 k;
uint16 l;
} ui_t, *pui_t;

void main(void)
{
struct ui_tag * ptr_ui;
struct ui_tag ** pptr_ui;
struct ui_tag ui = {0,0,0,0};

ptr_ui = &ui;
pptr_ui = (struct ui_tag **)&ptr_ui;
while(1);

}

Nov 14 '05 #9
> That doesn't seem very fruitful advice. He'd be better off trying to
understand the type system than trying to learn how to circumvent it.

Yep.
changing your debugging process from finding a syntax
error to figuring out why your computer is crashing :)


Finding the syntax error is much easier


Hence the smiley and the statement that he would have to figure out why the
computer is crashing (sarcasm... oops... my bad :)
pointer = (struct example_struct **pointer)&ex_p tr;


That cast is badly-formed, and requires a diagnostic.


Hmm... It compiles on my system... but from the other posts/responses I've
been participating in, I think my system might be broken. Could you please
elaborate?

typedef struct ui_tag {
uint16 i;
uint16 j;
uint16 k;
uint16 l;
} ui_t, *pui_t;

void main(void)
{
struct ui_tag * ptr_ui;
struct ui_tag ** pptr_ui;
struct ui_tag ui = {0,0,0,0};

ptr_ui = &ui;
pptr_ui = (struct ui_tag **)&ptr_ui;
while(1);

}

Nov 14 '05 #10

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

Similar topics

22
448
by: Lucas Machado | last post by:
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;
4
6205
by: bob | last post by:
I have little C experience and am concurrently trying to tackle C and LKM's (a little too ambitious maybe) anyway here is the problem I'm having with an example module I found. static int myintArray = { -1, -1 }; static int arr_argc = 0;
2
1740
by: Jim Carlock | last post by:
http:/ / aquaticcreationsnc . com/lib/php/test.php Remove the spaces to visit the link above... The w3 validator identifies the ampersand character as the leading character for special character sequences. And as such, all ampersands should be converted to &amp; when employed as part of a URI. So I configured that manually, for my own parameters. However, I think what I'm seeing here with the validator, is that the validator does not...
5
7811
by: A. Farber | last post by:
Hello, I call readv() and writev() in several spots of a program which I run under Linux, OpenBSD and Cygwin. Since it always the same way (check the return value; then check errno and retry if EAGAIN/EINTR), I've written a wrapper function (full source code on the bottom) to call those functions and just pass the function pointer to it: do { ...
3
7621
by: Suyash Upadhyay | last post by:
Hello all, I was writing a code regarding offset of structure elements. struct a { struct b { int i; float f; char ch; }x;
6
4123
by: Paul Edwards | last post by:
The following code: int main(void) { char *x; (void **)x += 1; return (0); }
4
9060
by: mdh | last post by:
May I ask why this works: given: char s; char *posbfr = s; char *endbfr = s + MAXOP; void(...){ if (posbfr >= endbfr) printf("......");
1
3763
by: yyhkitty | last post by:
Hi, I keep getting two invalid lvalue in assignment errors. here's what my code looks like: pthread_t msg_receive(char *sbuffer, int *maxlen) { // get the values for sbuffer and maxlen strcpy(sbuffer, current->message); &maxlen = current->messagelen; // invalid lvalue here }
11
2499
by: markryde | last post by:
Hello, Followed here is a simplified code example of something which I try to implement; in essence , I want to assign a value to a return value of a method is C. I know, of course, that in this example I can get this by newskb->iph = iphdr (this also appears in a commented line in the example below) ; but I want to achieve the same where the left side is : ip_hdr(newskb). Alas, if I try this , I get a compilation error about line 25....
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
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
6210
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
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
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
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.