Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Re: pointers... (http://www.velocityreviews.com/forums/t313804-re-pointers.html)

Emmanuel Delahaye 06-25-2003 02:49 AM

Re: pointers...
 
In 'comp.lang.c', "geo" <geometrikal@hhoottmmaaiill> wrote:

> struct random_struct {
> .....
> .....
> .....
> }
>
> struct random_struct random;
>
> and then i had a function which used this structure. What is the best
> programming practice:
>
> void function(struct random_struct * r) {
> .......
> }
>
> function(&random);


Yes, or

void function(struct random_struct const * r) {

for read-only access.

> or:
>
> void function(struct random_struct r) {
> .......
> }
>
> function(random);


No.

> and why?


Because the structure is copied. Can be a way to protect the original, but
'const' with a pointer is enough for that. The copy can be dangerous (the
automatic memory is small) and it's slow ad useless.

However it is acceptable for small ojects (one or two int), specially for
return.

--
-ed- emdelYOURBRA@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-library: http://www.dinkumware.com/htm_cl/index.html
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
--
comp.lang.c.moderated - moderation address: clcm@plethora.net


All times are GMT. The time now is 02:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.