On Fri, Dec 11, 2015 at 09:01:19AM +0100, aitor_czr wrote: > Hi Katolaz, > > Here you are an example of two arguments (x,y) passed by reference:
[cut] > > void func(int *x, int *y) > { > int k = *x; > *x = *y; > *y = k; > } > > This is the output: > > i = 1 j = 2 > i = 2 j = 1 > Dear Aitor, as many have already explained, this is not passing by reference, but passing by value. Then it happens that the value is a pointer and, as I already said in a previous email, this is a mechanism which *mimics* a pass-by-reference through a pass-by-value. This is not being pedantic, but calling things with their name, and avoiding confusion. Pass-by-reference is what is normally used in Java or in C++ (in the latter case, you have to use the "&" qualifier in the signature of a function/method to signalling the choice between pass-by-value and pass-by-reference). C is one of the few remaining languages which is consistent about allowing only one of the many possible argument passing mechanisms. And the mechanism chosen by C is pass-by-value. Fullstop. > On 12/10/2015 06:33 PM, dng-requ...@lists.dyne.org wrote: > >On Thu, Dec 10, 2015 at 05:00:58PM +0100, aitor_czr wrote: > >>>No, Katolaz, passing by value and passing by reference exist in C, > >>>at least in C99. > >>> > >Could you please give a pointer to the place where this feature is > >documented in the ANSI C99 standard? > > Passing by value and passing by reference in ANSI C99 are documented > in the following book: > > C - The Complete Reference (by Herbert Schildt) > Oh dear, that explains a lot. Shitty book, IMHO, quite inaccurate, full of mistakes and misconceptions, among which pass-by-reference is just one little example. If you want to get a serious introduction to C, then you are better off with the classical Kernighan & Ritchie, which covers only C90, though. A good, competent, and complete introduction to C99 is given in "C in a Nutshell", Prinz & Crawford, O'Really (2005). But don't expect an easy read through either of them. The best advice I have ever received about C is that I must not just buy "any" book about C and assume it is "the bible" or represents accurately what C is or is not. Except that book is the K&R. HND KatolaZ -- [ Enzo Nicosia aka KatolaZ --- GLUG Catania -- Freaknet Medialab ] [ me [at] katolaz.homeunix.net -- http://katolaz.homeunix.net -- ] [ GNU/Linux User:#325780/ICQ UIN: #258332181/GPG key ID 0B5F062F ] [ Fingerprint: 8E59 D6AA 445E FDB4 A153 3D5A 5F20 B3AE 0B5F 062F ] _______________________________________________ Dng mailing list Dng@lists.dyne.org https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng