f



pointer of pointer

Hi

I have a structure, B_t is another structure

typedef struct{
 int len;
 unsigned char code[12];
 B_t *b;
}A_t

Now I need to pass A_t into a function to evaluate
I use pointer of pointer

void evaluate(A_t **a)

My question is how to evaluate the component of this structure

(*a)->b???

seems not right

Thanks a lot!

0
qianz99 (12)
5/11/2007 8:36:52 PM
comp.lang.c 30656 articles. 5 followers. spinoza1111 (3246) is leader. Post Follow

6 Replies
952 Views

Similar Articles

[PageSpeed] 17

<qianz99@gmail.com> wrote in message 
news:1178915812.306611.242380@y80g2000hsf.googlegroups.com...
> Hi
>
> I have a structure, B_t is another structure
>
> typedef struct{
> int len;
> unsigned char code[12];
> B_t *b;
> }A_t
>
> Now I need to pass A_t into a function to evaluate
> I use pointer of pointer
>
> void evaluate(A_t **a)
>
> My question is how to evaluate the component of this structure
>
> (*a)->b???
>
> seems not right
>
It is right. It is ugly and so you might be better off with

A_t *aptr;
aptr = *a;

aptr->b;

Code that a machine can read correctly isn't necessarily easy for humans to 
read. The extra variable will almost certainly be optimised away by the 
compiler, so there is unlikely to be any efficiency penalty.
-- 
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

0
regniztar (3128)
5/11/2007 8:51:43 PM
On May 11, 1:36 pm, qian...@gmail.com wrote:

> My question is how to evaluate the component of this structure
>
> (*a)->b???
>

It accesses member b of A_t, which a pointer to B_t.  Whether
it is right or not depends upon what you mean by 'evaluate'.

JG

0
jgu222 (34)
5/11/2007 9:18:35 PM
"Malcolm McLean" <regniztar@btinternet.com> ha scritto nel messaggio 
news:g7WdnXdJF8HbStnbnZ2dnUVZ8tWnnZ2d@bt.com...
>>
> It is right. It is ugly and so you might be better off with
>
> A_t *aptr;
> aptr = *a;
>
> aptr->b;
>
> Code that a machine can read correctly isn't necessarily easy for humans 
> to read. The extra variable will almost certainly be optimised away by the 
> compiler, so there is unlikely to be any efficiency penalty.

I can't see how that is so much clearer than (*a)->b than you
claim. I can't see any way fou a human to misinterpret such an
expression. 


0
please.ask (434)
5/12/2007 12:19:30 PM
"Army1987" <please.ask@for.it> wrote in message 
news:f24bcb$q7b$1@tdi.cu.mi.it...
>
> "Malcolm McLean" <regniztar@btinternet.com> ha scritto nel messaggio 
> news:g7WdnXdJF8HbStnbnZ2dnUVZ8tWnnZ2d@bt.com...
>>>
>> It is right. It is ugly and so you might be better off with
>>
>> A_t *aptr;
>> aptr = *a;
>>
>> aptr->b;
>>
>> Code that a machine can read correctly isn't necessarily easy for humans 
>> to read. The extra variable will almost certainly be optimised away by 
>> the compiler, so there is unlikely to be any efficiency penalty.
>
> I can't see how that is so much clearer than (*a)->b than you
> claim. I can't see any way fou a human to misinterpret such an
> expression.
By itself it is not too bad, as long as the reader is familiar with C.
The problem comes when it is incorporated into longer expressions. You can 
very easily produce code which is perfectly machine parseable, but too hard 
to read.
-- 
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

0
regniztar (3128)
5/12/2007 10:25:56 PM
Malcolm McLean wrote:
> 
> "Army1987" <please.ask@for.it> wrote in message
> news:f24bcb$q7b$1@tdi.cu.mi.it...
>>
>> "Malcolm McLean" <regniztar@btinternet.com> ha scritto nel messaggio
>> news:g7WdnXdJF8HbStnbnZ2dnUVZ8tWnnZ2d@bt.com...
>>>>
>>> It is right. It is ugly and so you might be better off with
>>>
>>> A_t *aptr;
>>> aptr = *a;
>>>
>>> aptr->b;
>>>
>>> Code that a machine can read correctly isn't necessarily easy for
>>> humans to read. The extra variable will almost certainly be optimised
>>> away by the compiler, so there is unlikely to be any efficiency penalty.
>>
>> I can't see how that is so much clearer than (*a)->b than you
>> claim. I can't see any way fou a human to misinterpret such an
>> expression.
> By itself it is not too bad, as long as the reader is familiar with C.
> The problem comes when it is incorporated into longer expressions. You
> can very easily produce code which is perfectly machine parseable, but
> too hard to read.
>

The problem is they are easy too write at the time.  Too few developers
invest the time go back and refactor what they have written once it "works".

-- 
Ian Collins.
0
ian-news (10155)
5/12/2007 10:31:44 PM
"Ian Collins" <ian-news@hotmail.com> wrote in message 
news:5amtktF2p4etuU3@mid.individual.net...
> Malcolm McLean wrote:
>>
>> "Army1987" <please.ask@for.it> wrote in message
>> news:f24bcb$q7b$1@tdi.cu.mi.it...
>>>
>>> "Malcolm McLean" <regniztar@btinternet.com> ha scritto nel messaggio
>>> news:g7WdnXdJF8HbStnbnZ2dnUVZ8tWnnZ2d@bt.com...
>>>>>
>>>> It is right. It is ugly and so you might be better off with
>>>>
>>>> A_t *aptr;
>>>> aptr = *a;
>>>>
>>>> aptr->b;
>>>>
>>>> Code that a machine can read correctly isn't necessarily easy for
>>>> humans to read. The extra variable will almost certainly be optimised
>>>> away by the compiler, so there is unlikely to be any efficiency 
>>>> penalty.
>>>
>>> I can't see how that is so much clearer than (*a)->b than you
>>> claim. I can't see any way fou a human to misinterpret such an
>>> expression.
>> By itself it is not too bad, as long as the reader is familiar with C.
>> The problem comes when it is incorporated into longer expressions. You
>> can very easily produce code which is perfectly machine parseable, but
>> too hard to read.
>>
>
> The problem is they are easy too write at the time.  Too few developers
> invest the time go back and refactor what they have written once it 
> "works".
>
My current policy is to publicly release all reuseable code. So that forces 
me to clean it up and modularise it. However it is easier said than done. 
I've got an awful lot of stuff hanging around which for various reasons 
hasn't made it onto the website.
-- 
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
 

0
regniztar (3128)
5/13/2007 12:16:38 AM
Reply:

Similar Artilces:

pointers, pointers, pointers...
Hi There, I came up with following sample code to demonstrate my issue: #include <18F87K22.h> #device HIGH_INTS=TRUE, adc=16, ICD=TRUE #fuses NOWDT //No Watch Dog Timer #fuses WDT128 //Watch Dog Timer uses 1:128 #fuses HSM //Hi-Speed crystal oscillator #fuses NOBROWNOUT //No brownout reset #fuses NOPLLEN //No PLL enabled #fuses BBSIZ1K //1K words Boot Block size #fuses NOXINST //Extended set extension and Indexed typedef struct{ int8 foo, test; } Th...

Pointers, pointers, pointers.......
Hi group. Asking again some help to better understand the basic principles of RPL.... In RPLMAN they say: >>>In the most general definition of RPL, I is an object pointer >>>pointing to a composite object that is the top of a stack of >>>composite objects called the runstream. >>>R points to the rest of the runstream stack. What is really meant by *the rest of the runstream* ? Is R pointing to the object right after the one pointed by I? Is R pointing to the rest of the stack *as a whole* (how's it possible?) Anything else I didn't catch? >>...

C to M2 ... Any pointers on Pointer to Pointer conversion?
Hi, I'm trying to do up some socket libraries for XDS. So I'm trying to convert C programs to Modula-2 to test them. In the book Beginning Linux Programming by Neil Matthew and Richard Stones (Wiley) I'm stumped by some code relating to Pointers to Pointers. The original C source is at http://linux.aliboom.com:8000/getname.c.html and since I don't know how well what I am about to paste will be formatted, there is also a copy at http://linux.aliboom.com:8000/getname.mod.html I have two questions, the first one deals with the C code shown shortly after the firs...

c++: pointers to pointers
Hi, I have an array of pointers defined as such: myArray** ptr = new myArray[10]; for some reason i get a compile time error stating there is no default constructor for myArray. The problem is that i should not need to define one since myArray is a pointer to a pointer and so should not have a default constructor - its a primitive data type and not an object. Any help appreciated. Regards, A A wrote in news:3f9e5e27_1@news.iprimus.com.au: > Hi, > > I have an array of pointers defined as such: > > myArray** ptr = new myArray[10]; myArray** ptr = new myArray *[10]; &g...

Pointer to pointer or reference to pointer
The way I understand it Reference To pointer as function parameter eg. void RP(int *&rpMem) {} rpMem is actually an alias for the pointer outside the function right? So I would access it exactly with the same syntax just like outside pointer right? e.g. void RP(int &*rpMem) { *rpMem = 125; rpMem++; } int Mem = 123; int *pMem = &Mem; // pMem = for example 5000 *pMem = 124; // Mem = 124; RP(pMem); // Mem = 125, pMem = 5004 Is the above correct? A <a@a.a> wrote: > e.g. > > void RP(int &*rpMem) > { > *rpMem = 125; > rpMem++; &g...

pointer vs pointer to pointer
AIM: To write a queue with 3 operations. WHAT I GOT: It works PROBLEM: Have a question: Why do "pointer to pointer" in enqueue() and "a pointer" to deleteElement() both work fine ? Will enqueue() work fine if I pass just "a pointer" to it ? Will deleteElement() work fine if I pass "pointer to pointer" ? /* A queue implementataion with the operations that I need: * (1) Add element to the front of the queue * (2) remove an element with a unique ID (string constant) * (3) compare 2 elements (string comparison) * (4) print queue * ...

Pointer-to-pointer-to-pointer question
The code example below shows the dynamic allocation of a 2D array. I must admit that it took quite a while for me to get there (I already have another posting to that effect), but I am glad that I finally got it working. Now here's the problem: I am able to get the 2D array dynamically allocated correctly as long as I am doing it "in-line" (i.e. without invoking any function). The moment I try to do it in another function, I get a core dump. Any help will be appreciated. Since this function is expected to update a pointer-to-pointer type, I am actually passing the pointer-...

Matlab, pointers and pointers to pointers
Matlab stores matrices using simple pointers in order to allocate memory. Using pointers to pointers, according to my experience, we could obtain the following benefits: - code would run faster (I think up to 70%) - memory would be allocated in a better way Why this solution is not used? There are some limitations? Luigi Luigi: <SNIP longing for pointers - not to heaven - to memory... > Why this solution is not used? There are some limitations... <luigi> a fact of life that we all have to live with: it IS just NOT happening... -or- at least it is not happening since 1984... d...

Pointers to pointers
How can you use a "pointer to a pointer" as a two dimensional array using 'new' and 'delete' rather than 'malloc' and 'free'? Thanks, Jonas Jonas Cord wrote: > How can you use a "pointer to a pointer" as a two dimensional array > using 'new' and 'delete' rather than 'malloc' and 'free'? Pretty much the same. int main() { int** data; data = new int*[100]; for (int i = 0; i < 100; ++i) data[i] = new int[100]; //use it for (int i = 0; i < 100; ++i) delete []...

pointers to pointers
Hi, i understood what pointers are and all stuff, and now i'm at the part with pointers to pointers and my book doesn't really help on this issue. let be: int a,*p,**q; how to make use of **q,*q and q ? Which who's address and/or who's value contains. I would like some examples like p=&a;// p contains the address of a and *p contains it's value but regarding **q,*q respectively q. Thanks. apropo wrote: > Hi, > i understood what pointers are and all stuff, and now i'm at the part > with pointers to pointers and my book doesn't really help on...

Pointers for these pointers...?
Hi Everyone: I'm trying to develop a property list to include as metadata about my object classes. i.e. I want each class I'm developing to include a PropertyList which will contain ObjectProperty pointers. ObjectProperty is a class containing the typeid.name() of a type as it's ObjectType as well as an ObjectName and ObjectDescription. Basically 3 strings of metadata describing each of a class' member variables (and hopefully functions) so that the class can report to a query from another class what properties it has available for access at run time. Here is what I have and t...

More on pointers to pointers.
I suspect I'm missing a broader concept here. Okay, given the following code: #include <stdio.h> int main(void) { char *ptr[] = {"Garbage", "test", "work"}; char **arg; arg = ptr; printf("The string is: %s\n", ptr[1]); return 0; } Why am I not allowed to do something like: arg = &ptr; ? I guess even more to the point, why is this legal? arg = &(*ptr) ; Chad Chad said: > I suspect I'm missing a broader concept here. Okay, given the following > code: > > #include <stdio.h> > > in...

Pointer to Pointer or not?
Hi I am creating my own Queue class to learn about Queues and pointers. I have come across a question of two styles and I don't know if there are any dangers associated with them. I coded my remove function as follows template <class T> bool adsQ<T>::Remove(T* theData) { Qnode<T>* removeNode = 0; if (true == isEmpty()) { //cout << "False" << endl; return false; } else { /* What I am trying to achive here is to change the data pointed to by theData to the data pointed to by pData.*/ *theData =*(pHead->pData); //Data exchan...

pointer to pointer
I have only used pointer to a pointer while manipulating arrays of arrays. I have not seen any C++ libraries that use pointer to a pointer as a function parameter. But I have seen it used in COM. If we want the function to create a new object and allow the passed in pointer to point to the object created we can pass a pointer to the reference. Is there anything special about COM that it needs pointer to a pointer. Is this becuase that COM can be used from C as well and we don't have references in C. In what other circumstances pointer to pointer can be used. Why don't we never see poi...

pointer to pointer
Its just a very simple and basic program to learn exactly what is described in comments here. Can you provide a better (and short) exercise ? /* A program to learn how to use a pointer to a pointer. Here we take an array of char pointers. A char* in the array, of course, points * to some char. Array has only one element. We change the value of char pointed by array's element using a function. * * VERSION 0.0 */ #include <stdio.h> void replace_char_value(char* [], char); int main(void) { char* arrc[2] = {0}; char c = 'c'; arrc[0] = &c;...

pointer to pointer
hi could someone tell me a good website that explains pointer to pointers well. Not just simple stuff like 2d arrays passing , or pointing to another int variab.le jagguy wrote: > hi > could someone tell me a good website that explains pointer to pointers well. > Not just simple stuff like 2d arrays passing , or pointing to another int > variab.le > > Not sure that there is one - how hard can it be really. *p returns a reference to whatever p points to. If p points to a pointer, **p returns a reference to whatever that pointer points to. There's one for func...

pointer to a pointer
My situation: I have a function that takes a pointer to an FSref as an argument. In the body of the function is a function call that also takes a pointer to an FSRef. I need to pass my original FSRef, but since I have only a pointer to it, I am assuming I need to dereference it twice when I call the second function. However, using something like &&myFSRef in the second function doesn't work. Can anyone tell me the proper way to do this? Thanks. In article <1105802448.cd52b3255e6c95476ce23f7be215a6a3@teranews>, Steven Daedelus <sdaedelus@ira.gov> w...

Pointer to a pointer to a pointer to a member function
Hi, I'm having a problem compiling the following snippet with MSVC++ 7.1 and I'm not sure if it is a compiler bug? (or I am being stupid) struct Vector3 { float x, y, z; }; void blah() { static Vector3 (Vector3::*function)(float); static Vector3 (Vector3::**_function)(float) = &function; /*static*/ Vector3 (Vector3::***__function)(float) = &_function; *__function = &function; } If I uncomment the 'static' qualifier it then compiles fine? (Or if I change the return type of the function pointers to an atomic type such as &#...

Pointer to pointer Vs References to Pointer
Q . When to use use pointer-to-pointer and reference-to-pointer to modify a pointer passed to a function ? According to me Which is better : double pointers OR Reference to Pointer ? There is no clear advantage and depends on programmer =91s choice or habit . As Nilesh mentioned =94 Reference to pointer=94 makes code easy But Pointer to pointer makes code easy to understand. So one can use any one . Why Pointer to Pointer is generally used ? 1. Pointer to pointer can be used in C and C++ but reference to pointer is limited to C++. a. Generally people start learning programming from C . So they get used to pointer to pointer. b.Pointer to Pointer usage makes project porting in C or C++ easy. 2. Generally libraries uses pointer to pointer approach like COM uses pointer to pointer for CoCreateInstance or QueryInterface. Fourm : Could you please let me know if these are the only reasons or i am missing something? Thanks Vikrant Example #include "stdafx.h" void Ref2Poi(int * &p) { *p =3D 10; } void Poi2Poi( int ** p) { **p =3D 10; } int _tmain(int argc, _TCHAR* argv[]) { int i =3D 13; int j =3D 14; int *p =3D &i; int *q =3D &j; Ref2Poi(p); Poi2Poi(&q); return 0; } "bansalvikrant@gmail.com" <bansalvikrant@gmail.com> writes: > Q . When to use use pointer-to-pointer and reference-to-pointer to > modify a pointer passed to a function ? &g...

Void Pointers to Void Pointer Arrays in C++
Ok I am writing a program in Visual C++. I have a void pointer that points to an array of void pointers. I have a variable that tells me how many elements are in the array of void pointers, but I cannot figure out how to dereference them. How do I where one element in my array of void pointers points to? Thanks in advance Brett Hello "Brett Verhagen" <kalluminati2001@yahoo.com> wrote in message news:2a17d8f5.0308052101.4361bce9@posting.google.com... > Ok I am writing a program in Visual C++. I have a void pointer that > points to an array of void pointers. I have a va...

Matlab-C++ interface
Hello, I have a function in C++ with a pointer of pointers as argument. How can I use this function in Matlab? Here is the code of the Matlab-C++ interface: #include "mex.h" #include "EEUtils_.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { //protoype of the called function double* REEsum(int, int, int, double, double**); //input data for the called function REEsum int m; int N; int kmax; double q; double *points; double *Icpp; /* assign pointers to each input */ kmax = (int) mxGetScalar(prhs[0]); q =...

pointer c++//C#
Hi until recently I only knew some VB.NET and there were no pointers. Now I understand how to use them but still wonder why exactly they are needed? What do they look like in C#? Thanks and cheers Michael mikethebike wrote: > until recently I only knew some VB.NET and there were no pointers. Now > I understand how to use them but still wonder why exactly they are > needed? Uh... Because it would be harder without them, maybe? > What do they look like in C#? Ask in a C# newsgroup or get a book and look it up. V -- Please remove capital 'A's when re...

pointers to pointers question
How come something like: #include <stdio.h> int main(int argc, char **argv) { char **arg; int i; for ( i = 0; argv[i] != NULL; ++i ) { puts(argv[i]); } for ( arg = argv; *arg != NULL; ++arg ) { puts(*arg); } return 0; } doesn't require a explicit & before argv in the for loop, but something like #include <stdio.h> #include <stdlib.h> int main(void) { char *ptr = "Garbage"; char **pptr; pptr = &ptr; printf("The value is: % s\n", *pptr); } does require an explict & Chad Chad w...

Use of Pointer of Pointer
Hi all. I am little bit confsused with the way pointer is working. First of all what is the difference between int &Number = 10; and int *Number; One more question ... void Copy(char **word) { *word = [some pointer to a string]; } when calling this function with char **sentence; Copy(sentence); //Here the application crashes but when calling this function with char *sentence; Copy(&sentence); //Here it works fine. What is wrong i do in the first call of function. Thanks in advance Rajat int &Number = 10; shouldn't work since you are trying to assign a literal to...

ctypes pointer to pointer
Hi, I have a C function in the dll does the following: DLL_API int dll_foo(char **data, size_t *size) { strcpy(*data, "hello"); *size = strlen(*data); return 0; } So I would call the function as such, char data[8]; size_t size; int status = dll_foo(&data, &size); I have tried the following in Python but not able to get it working... Any help would be appreciated! from ctypes import * mydll = windll.mydll array = c_char * 8 data = array() size = c_long() status = mydll.dll_foo(byref(data), byref(size)) Traceback (most recent call last): File "<in...

Web resources about - pointer of pointer - comp.lang.c

The Pointer Sisters - Wikipedia, the free encyclopedia
The Pointer Sisters are an American R&B recording girl group from Oakland , California that achieved mainstream success during the 1970s and ...

Michael Pointer (@michaelpointer) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Thread: I'm looking for pointers to a Google Maps API overview.
... outline for a map, making it super-easy to edit, and also to have it in the most convenient form for someone browsing over the data. Any pointers ...

Alpha Range ~ LaserVRâ„¢ laser pointer target shooting game! for iPhone 3GS, iPhone 4, iPhone 4S, iPod ...
Get Alpha Range ~ LaserVRâ„¢ laser pointer target shooting game! on the App Store. See screenshots and ratings, and read customer reviews.

German Shorthaired Pointer Dog Hates Alarm Clock - YouTube
This is my dog Adenine, a German Shorthaired Pointer, waking up to my alarm in the morning. He hates the alarm and howls at it until it turns ...

Shark patrol chopper back in the air - as white pointer closes beaches
Perth's shark patrol helicopter took off for its first flight of the season on Saturday morning - as a great white menaced City Beach and Floreat ...

Paul Gallen's pro boxing debut may be a pointer to the future
Cronulla captain Paul Gallen will confirm at a press conference on Friday that his first professional boxing bout will be on the Geale-Wood undercard ...

Inside mail: All the big bets, market movers, work whispers, trial pointers and quaddies for Rosehill ...
ALL the big bets, market movers, work whispers, trial pointers and quaddie tips for Rosehill on Saturday.

Esperance shark attack survivor Sean Pollard recalls how he fought off white pointer - PerthNow Search ...
BUNBURY shark attack survivor Sean Pollard says he feels lucky to be alive after his miracle escape from a white pointer near Esperance.

Ray Allen Three Pointer - Heat V Spurs - Video
It appeared smooth and effortless, an example of pure "in the moment" sporting perfection.

Resources last updated: 3/12/2016 6:33:47 AM