[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, 02 Mar 2004 17:10:11 +0100, Jakob Oestergaard wrote:

> 
> 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.
> 
Øh, nu kan det godt være, der er noget, jeg har misforstået, men er
pass-by-reference ikke lig med, at man overfører adressen på en
parameter? I så fald hvad gør man så, når man i C overfører en
pointer som reference, eller eksplicit angiver, det er parameterens
adresse: 

#include <stdio.h>

void cbr(int *);

int main() {

int num = 5;

printf("%d\n",num);
cbr(&num);
printf("%d\n",num);

return 0;
}

void cbr(int *ptr) {
*ptr += 5;
}

Output:
5
10

-- 
Hilsen/Regards
Michael Rasmussen
--------------------------------------------------------------
Be different: conform.




 
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] *