Now you can ponder upon pointer to pointer to pointer to pointer which I frequently use in a middleware I wrote 20 years ago.
;-)
(Hint: It's a way of implementing C++ like classes in plain C. Now the debugger can handle it, but back then it failed after 3 pointer levels.)
/Joakim
-----Original Message-----
From: c400-l-bounces@xxxxxxxxxxxx [mailto:c400-l-bounces@xxxxxxxxxxxx] On Behalf Of Frank Kolmann
Sent: den 4 april 2014 10:14
To: c400-l
Subject: [C400-L] First C program
Hi Jevgeni
WOW, many thanks. I have updated the program.
Proves I still dont understand pointers, especially when to use a pointer to pointer.
I definitely did not want to use global. It was all I could get to work.
I did some more learning and I found this, here
http://www.eskimo.com/~scs/cclass/int/sx8.html
'What are pointers to pointers good for, in practice? One use is returning pointers from functions,
'via pointer arguments rather than as the formal return value.
So the answer to my confusion is , when you want to return a pointer in a function arg,
you need a pointer to a pointer.
Frank
*Subject: Re: First C program
*From: Jevgeni Astanovski <Jevgeni.Astanovski@xxxxxxxxxxxxx>
*Date: Thu, 3 Apr 2014 11:17:52 +0000
If you want to open a file in a function and have its pointer available
in
main, you must pass pointer to pointer!
Something like this:
int main()
{
_RFILE *fp ;
openfile(&fp) ;
}
void openfile(_RFILE **fp)
{
*fp = _Ropen(...) ;
}
(Bad) Alternative is to have it defined as global variable.
--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list To post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/c400-l.
________________________________
Capgemini is a trading name used by the Capgemini Group of companies which includes Capgemini Sverige AB, a company registered in Sweden (number 556092-3053) whose registered office is at Gustavslundsvägen 131 Box 825 – S-161 24 Bromma.
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
As an Amazon Associate we earn from qualifying purchases.