473,480 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What this means? ---> struct resource *r = v, *p;

I found follow function in the Linux kernel (kernel/resource.c)

static int r_show(struct seq_file *m, void *v)
{
struct resource *root = m->private;
struct resource *r = v, *p;
int width = root->end < 0x10000 ? 4 : 8;
int depth;

for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p =
p->parent)
if (p->parent == root)
break;
seq_printf(m, "%*s%0*lx-%0*lx : %s\n",
depth * 2, "",
width, r->start,
width, r->end,
r->name ? r->name : "<BAD>");
return 0;
}

What's mean of ---> " struct resource *r = v, *p; "
Thanks.

Nov 14 '05 #1
4 2123

michael wrote:
I found follow function in the Linux kernel (kernel/resource.c)

static int r_show(struct seq_file *m, void *v)
{
struct resource *root = m->private;
struct resource *r = v, *p;
<snip>
What's mean of ---> " struct resource *r = v, *p; "
Thanks.


Read this statement as,
struct resource *r = v;
struct resource *p;

Nov 14 '05 #2
"michael" <mj***@mail.com> wrote:
What's mean of ---> " struct resource *r = v, *p; "


It's a normal declaration statement, containing the declarations of two
pointers to struct resource, one of which is initialised to v.

Richard
Nov 14 '05 #3

"michael" <mj***@mail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
I found follow function in the Linux kernel (kernel/resource.c)

static int r_show(struct seq_file *m, void *v)
{
struct resource *root = m->private;
struct resource *r = v, *p;
int width = root->end < 0x10000 ? 4 : 8;
int depth;

for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p =
p->parent)
if (p->parent == root)
break;
seq_printf(m, "%*s%0*lx-%0*lx : %s\n",
depth * 2, "",
width, r->start,
width, r->end,
r->name ? r->name : "<BAD>");
return 0;
}

What's mean of ---> " struct resource *r = v, *p; "
Thanks.


Horrible and confusing statement!

It's declaring two pointers, one being initialized
from the function argument.

They should be on separate lines.

It's probably fair to say you should always (at least
99.44% of the time)keep your declarations on separate lines.

That v,*P (to me anyway) can be easily confused with (v,*p), which
means evaluate v, then evaluate *p and return the value of *p. This
may be disallowed in initializers, though.

To further convince you to use separate lines, consider the following:

#define intpointer_t int*

intpointer_t a,b,c;

Will not give you 3 pointers to int, but one pointer to int (a)
while b and c are simple integers.

typedef int* intpointer_t;

intpointer_t a,b,c;

Will work as expected, but that doesn't make it a Good Thing.

Rufus


Nov 14 '05 #4
Rufus V. Smith wrote:
"michael" <mj***@mail.com> wrote in message
<snip>
Horrible and confusing statement!

It's declaring two pointers, one being initialized
from the function argument.

They should be on separate lines.

It's probably fair to say you should always (at least
99.44% of the time)keep your declarations on separate lines.

That v,*P (to me anyway) can be easily confused with (v,*p), which
means evaluate v, then evaluate *p and return the value of *p. This
may be disallowed in initializers, though.
The comma operator ',' has the least precedence of all operators.

int a, b = 5;
a = 10, b;

will always assign 10 to a.
To further convince you to use separate lines, consider the following:
<snip>


Regards,
Jonathan.

--
"We must do something. This is something. Therefore, we must do this."
- Keith Thompson
Nov 14 '05 #5

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

Similar topics

1
2246
by: verec | last post by:
Last week I asked here how I could detect that a T was polymorphic, and received very thoughtful and useful replies that I used straight away. Thanks to all who answered. This week, it turns...
5
3236
by: Frank Hauptlorenz | last post by:
Hello Folks, does anybody know what these message in the db2diag.log means: 2003-12-10-09.49.33.250000 Instance:DB2 Node:000 PID:812(db2syscs.exe) TID:772 ...
2
2484
by: beetle | last post by:
Hello, I'm storing data in several different binary tree's. The root node is located in a struct containing general data about the tree. struct lnode { char *fname; int nentry;
3
13252
by: Joe DeAngelo | last post by:
When I try to compile a source code which should normally run I got this error message error CS0246: The type or namespace name 'XmlSchemaSet' could not be found (are you missing a using...
9
1222
by: A.M | last post by:
Hi, I am analysing a VB.NET code and i see this line of code: Dim strCacheKey As String = & "provider" What is the role of ?
3
2699
by: rizzkhan | last post by:
Hello everybody, I am a bit confused about this operator -> could anybody explain this for me. The reason I am confused is that every document I read to get an explaination about it, explain it in...
7
1687
by: Manfred Kooistra | last post by:
I have these pieces of example code that I am trying to figure out: (a) $a = $b->c(); (b) $d->e(); What does "->" do? Where is there a reference/explanation in the PHP manual (or anywhere...
4
3217
by: giannis | last post by:
I am a newbie at VB. When i try to remove an item from the BindingSource and try to delete this item from the database: BindingSource.RemoveCurrent() ...
6
1603
by: Victor | last post by:
i found some example js. the character $ has been used a lot. What's that mean? can someone give me some reference on that? Thanks
0
7049
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,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
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...
0
5348
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,...
1
4790
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...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.