CHDKPTP: for some - a sophisticated work - page 3 - General Discussion and Assistance - CHDK Forum

CHDKPTP: for some - a sophisticated work

  • 23 Replies
  • 14460 Views
*

Offline reyalp

  • ******
  • 14125
Re: CHDKPTP: for some - a sophisticated work
« Reply #20 on: 26 / March / 2019, 14:27:40 »
Advertisements
assigning the address to the single dereference of the double pointer within the function has the desired effect which is to correctly set the base address of the PTPParams structure within the single pointer outside of the function?
I'm not sure if this is what you are trying to say, but in C
Code: [Select]
*foo = x;
means store the value of x in the memory pointed to by foo.
Don't forget what the H stands for.

Re: CHDKPTP: for some - a sophisticated work
« Reply #21 on: 26 / March / 2019, 15:19:41 »
I'm not sure if this is what you are trying to say, but in C

Ok. Attempting to restate my quandary as follows.

If the code was restated as:

Code: [Select]
#define CHDK_CONNECTION_METHOD PTPParams *pointername; PTP_CON_STATE *ptp_cs; get_connection_data(L,1,&pointername,&ptp_cs);

/*
get pointers out of user data in given arg
*/
static void get_connection_data(lua_State *L,int narg, PTPParams **pointertopointername,PTP_CON_STATE **ptp_cs) {

    *pointertopointername = (PTPParams *)luaL_checkudata(L,narg,CHDK_CONNECTION_META);
    *ptp_cs = (PTP_CON_STATE *)((*params)->data);
}

Then this is false:

The Lua userdata is a void pointer (pointer to anything), which is cast to PTPParams pointer, and stored in params pointertopointername (which is a pointer to a PTPParams pointer, because it's an output parameter)

Since it is actually now stored in pointername i.e. pointertopointername dereferenced (which is a pointer to a PTPParams but not a pointer to a pointer to a PTPParams)

?
« Last Edit: 26 / March / 2019, 16:59:38 by andrew.stephens.754365 »

*

Offline reyalp

  • ******
  • 14125
Re: CHDKPTP: for some - a sophisticated work
« Reply #22 on: 26 / March / 2019, 16:58:49 »
Ok. Attempting to restate my quandary as follows. If the code was restated as:
...
Then this is false:
...
Since it is actually now stored in pointername (which is a pointer to a PTPParams but not a pointer to a pointer to a PTPParams)
I'm not sure I understand the quandary, but maybe you're taking the "and stored in params" more literally than I intended. I meant it in the sense of params as being an "output parameter". You are correct that the value of the user data will stored in the addressed pointed to pointertopointername, which effectively sets the value of pointername

While "output parameters" don't exist as a distinct concept in C, it's often convenient to just treat the "*" as a decoration needed to access the value of an output parameter when thinking about code like this.
Don't forget what the H stands for.

Re: CHDKPTP: for some - a sophisticated work
« Reply #23 on: 26 / March / 2019, 17:37:34 »
While "output parameters" don't exist as a distinct concept in C, it's often convenient to just treat the "*" as a decoration needed to access the value of an output parameter when thinking about code like this.

I usually just try to interpret what you say word for word (or character by character) to the best of my ability. While that has caused confusion on my part this time I think your most recent comment here gives me enough confidence to continue ("decorations" and  "output parameters" currently still seem like black magic here though).

Thanks.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal