Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/24/10 17:06
Read: times


 
#176903 - General pointer usage techniques
In playing with pointers to structs, I've noticed that accessing the members is indeed more expansive than accessing the members of a real object (i.e. not through a pointer de-reference). So, I've been experimenting with things like this:

static void put_event (event_t *pevent)
{
    event_t xdata ev;
    memcpy (&ev, pevent, sizeof (event_t));

    printf ("[%02bx-%02bx-%02bx]", ev.tm[RTC_MON], ev.tm[RTC_MDAY],
            ev.tm[RTC_YEAR]);
    printf ("(%02bx:%02bx:%02bx)", ev.tm[RTC_HOUR], ev.tm[RTC_MIN],
            ev.tm[RTC_SEC]);
    printf ("<%02bx><%-16.16s><%02bx><%s>n", ev.num,
            EVENT_DESC[ev.num], ev.data_id, &ev.dat[0]);
}
 


The memcpy is itself expensive, but using it this way creates a smaller function than just using the pointer. But, you can see this completely defeats the point of passing a pointer in the first place. I realize that I can probably memcpy call and just pass the structure which will force the compiler to do it for me, so overlook that bit unless there is something else that should be considered.

So, what is the general practice for 8051s (if one can generalize something like this); passing by value or reference?

I'm using the Keil compiler and a Silabs C8051F340 (single DPTR).

--David


List of 5 messages in thread
TopicAuthorDate
General pointer usage techniques            01/01/70 00:00      
   This is one of those architectural limitations            01/01/70 00:00      
      Reimplement the standard library functions?            01/01/70 00:00      
   re pointers            01/01/70 00:00      
      As ever...            01/01/70 00:00      

Back to Subject List