[Coco] question C++

John Kent jekent at optusnet.com.au
Thu Mar 22 00:11:19 EDT 2012


Sorry for all these posts

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 buff_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 write_count, uint8_t *valptr )
> {
>   int i;
>
>   h->inptr = &h->buffer[h->buff_count];
>   for( i=0; i<write_count; i++ )
>   {
>     *h->inptr++ = *valptr++;
>      h->buff_count++;
>   }
> }
>

actually write_buf is able to write multiple bytes, which is why it's 
passing the address of val.
In the example you gave it's only writing one 8 bit unsigned integer.

>
> write_count will be 1.
> 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