Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: pointers...

Reply
Thread Tools

Re: pointers...

 
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      06-25-2003
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- http://www.velocityreviews.com/forums/(E-Mail Removed) [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: (E-Mail Removed)
 
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