On Mar 16 2014 10:03 PM, Dave Hylands wrote:
> Hi John,
>
>
> On Sun, Mar 16, 2014 at 6:57 PM, John Kasunich 
> <[email protected]>
> wrote:
>>
>>
>>
>> On Sun, Mar 16, 2014, at 09:41 PM, Dave Hylands wrote:
>> > Hi,
>> >
>> > I'm jumping in late here, but why not just do:
>> >
>> > *(hal_data_u *)data_addr = pin->dummysig;
>> >
>> > which is a structure copy, and the compiler will optimize it to 
>> use the
>> > best way of copying based on the size?
>> >
>>
>> I didn't know you could copy structures like that in C.
>>
>> Does it work for any size structure?
>>
>> When was that added to the language?  I'm 99.4% certain
>> that in the K&R days you had to copy structs yourself.
>> Is it maybe a C99 thing?
>
> Many K&R variants didn't support structure copying. It was an 
> extension to
> K&R C:
> http://cm.bell-labs.com/cm/cs/who/dmr/cchanges.pdf
>
> It was introduced as part of the language specification when ANSI C 
> was
> introduced, so its been around for quite a while.
>
> It works with any size structure. IIRC gcc uses memcpy (or a function 
> like
> memcpy) for large structures and optimizes it to do word copies for 
> small
> structures.
>
> I've used it for many many years (I learned C using K&R in 
> university, but
> fortunately never had to actually use it for working).
> Function prototypes made C manageable :)

Yes, but you need to be careful and make sure that it will do what you 
want.  For fairly flat structures:

struct bla {
   int some, thing;
   float more;
}

it will do fine, but for:

struct woof {
   struct bla *bla1, *bla2;
   char *names[];
}

you do not know apreori if you should do a deepcopy or shallow (ie do 
you copy the pointers, or do you follow down the pointers and copy all 
the subrecords).

Other than that, it is a very useful feature.

   EBo --

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to