Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > AnyClass

Reply
Thread Tools

AnyClass

 
 
Richard Herring
Guest
Posts: n/a
 
      10-18-2004
In message <(E-Mail Removed)> , Jerry
Coffin <(E-Mail Removed)> writes
>JKop <(E-Mail Removed)> wrote in message
>news:<0Cxbd.33431$(E-Mail Removed)>...
>
>[ ... ]
>
>> > The bottom line is pretty simple: memcpy works in bytes, so you need
>> > to specify its arguments in bytes. You'd use the number of elements if
>> > you were using a function (or template) that works in the number of
>> > elements, such as some in the C++ standard libary (e.g. std::fill_n --
>> > std::copy uses iterators to specify the starting and ending points).

>>
>> memcpy( y, x, getcount(array) * sizeof(array[0]) );

>
>IMO, this is just a roundabout way of getting back to where we started
>-- getcount is normally defined something like:
>
>#define getcount(array) (sizeof(array)/sizeof(array[0]))
>
>So you're doing:
>
>sizeof(array)/sizeof(array[0]) * sizeof(array[0])
>
>and the sizeof(array[0])'s cancel, giving sizeof(array).
>
>The bottom line is that if you intend to copy the entire array, you
>might as well just specify "sizeof(array)" and be done with it.
>

Except that if getcount() is a template function rather than a macro,
you can use template techniques to check that its argument really is an
array and not something that's accidentally decayed to a pointer.

--
Richard Herring
 
Reply With Quote
 
 
 
 
JKop
Guest
Posts: n/a
 
      10-18-2004

> Except that if getcount() is a template function rather than a macro,
> you can use template techniques to check that its argument really is an
> array and not something that's accidentally decayed to a pointer.



I like!


-JKop
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments