[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Performance: C contra ADA



On Tue, Mar 02, 2004 at 02:12:58PM +0100, Michael Rasmussen wrote:
> Hej alle,
> 
> Et lidt langhåret spørgsmål rent sprogdesign mæssigt:
> 
> I C foregår parameteroverførsel med call-by-reference

Nej. I C++ kan man angive by-reference overførsel af parmetre, mens
konceptet slet ikke eksisterer i C.

Til overførself af f.eks. strukturer i C vil man typisk overføre
(by-value!) en *pointer* til strukturen.  Hvis man så de-refererer
pointeren og arbejder på den resulterende struktur, vil det have samme
effekt som hvis man havde overført strukturen by-reference.

Det gør man typisk, fordi det er relativt billigt at lave by-value
overførsel af små datasæt (f.eks. en pointer), mens det er dyrt at lave
by-value overførsel af store datasæt (f.eks. en struktur).

Men; by-reference eksisterer ikke i sproget C. I C++ er muligheden der,
men det skal angives eksplicit.


struct my_struct {
  int a, b, c, d, e, f, g;
  double p, q, r, s, t;
};

/* dyrt kald i C */
int f(struct my_struct s) { return s.a; }

/* billigt kald i C  - kræver dereferering ved brug af s! */
int g(const struct my_struct *s) { return s->a; }

/* billigt kald i C++ - by-reference overførsel */
int h(const my_struct &s) { return s.a; }


 / jakob




 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *