[Coco] question C++
John Kent
jekent at optusnet.com.au
Wed Mar 21 23:54:55 EDT 2012
On 22/03/2012 2:50 PM, John Kent wrote:
>
>
> On 22/03/2012 1:30 AM, Mark McDougall wrote:
>> On 22/03/2012 12:03 AM, Luis Fernández wrote:
>>
>>> ANYONE can tell me the meaning& here
>>> write_buf (h, 1,& val);
>>
>> The '&' is the 'address of' operator, so it passes the address of the
>> 'val' variable.
>>
>>> static void write_buf_const (dmk_handle h, int count, uint8_t val)
>>> {
>>> while (count--)
>>> write_buf (h, 1, &val);
>>> }
>>
>> This looks like it writes 'count' number of pad bytes of value 'val'.
>>
>> Regards,
>>
>
> val is passed on the stack to the write_buf_const procedure.
> I assume dmk_handle is a type definition for a structure pointer type
> for the buffer.
> "handle" I suspect refers to a pointer type.
>
> so you might have something like
>
> struct dmk_buff {
> unit8_t *inptr;
> unit8_t *outptr;
> int count;
> uint8_t buffer[MAX_BUF_SIZE]]
> };
>
> typdef struct dmk_buff *dmk_handle;
>
> although the _t in uint8_t indicates that it is a type definition, and
> dmk_handle does not indicate it's a type definition, but I assume it is.
>
> anyway .... what it seems to be doing is passing the address of val to
> the write_buf routine and the write_buf routine will access val via
> it's address passed as a pointer value . i.e.
>
> void write_buf( dmk_handle h, int fill_count, uint8_t *valptr )
> {
> int i;
>
> h->inptr = &h->buffer[h->count];
> for( i=0; i<fill_count; i++ )
> {
> *h->inptr++ = *valptr;
> h->count++;
> }
> }
>
>
> unit8_count will be 1.
sorry fill_count will be 1 (I renamed the variable).
> write_buf will fetch val, using it's address and write it to the
> buffer via the input pointer
>
> h->count mean that h is pointing to a structure contain a member
> variable "count".
>
> I hope that's right.
>
> John.
>
--
http://www.johnkent.com.au
http://members.optusnet.com.au/jekent
More information about the Coco
mailing list