PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > struct having pointers's object being passed by value to afunction...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
struct having pointers's object being passed by value to afunction...

Réponse
 
LinkBack Outils de la discussion
Vieux 05/02/2008, 06h56   #1
Rahul
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut struct having pointers's object being passed by value to afunction...

Hi Everyone,

It is possible to pass a structure to a function by value in c just
like how class is being passed to functions by value in c++.
c++ introduces the copy constructor for this very purpose of making
sure deep copy is performed on c++ objects which have pointers
pointing to some memory location.

It is very much possible to have a c structure having a pointer, how
does c solve the problem? making sure deep copy is done?

Thanks in advance!!!
  Réponse avec citation
Vieux 05/02/2008, 07h00   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: struct having pointers's object being passed by value to afunction...

Rahul wrote:
> Hi Everyone,
>
> It is possible to pass a structure to a function by value in c just
> like how class is being passed to functions by value in c++.
> c++ introduces the copy constructor for this very purpose of making
> sure deep copy is performed on c++ objects which have pointers
> pointing to some memory location.
>
> It is very much possible to have a c structure having a pointer, how
> does c solve the problem? making sure deep copy is done?
>

It doesn't, you get a shallow copy.

Why would you want to pass such a structure by value?

--
Ian Collins.
  Réponse avec citation
Vieux 05/02/2008, 07h07   #3
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: struct having pointers's object being passed by value to a function...

Rahul said:

> Hi Everyone,
>
> It is possible to pass a structure to a function by value in c just
> like how class is being passed to functions by value in c++.
> c++ introduces the copy constructor for this very purpose of making
> sure deep copy is performed on c++ objects which have pointers
> pointing to some memory location.
>
> It is very much possible to have a c structure having a pointer, how
> does c solve the problem? making sure deep copy is done?


C doesn't solve the problem. C assumes you know how to solve the problem.

(It's not difficult. Step 1: write a "copy constructor" function. Step 2:
call it to create a copy. Step 3: use the copy. Step 4: destroy the copy
when you're done with it.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h01.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09366 seconds with 11 queries