[Gambas-user] Working with .so library

Cedron Dawg cedron at exede.net
Mon Jun 24 17:26:09 CEST 2019


The question was why would a language require that kind of complexity.  I don't think it all that complex once you understand it.  However, the apparent complexity in this case is dealing with a pointer to a pointer.  Well, had C been implemented with a pass by reference convention this complexity in this case wouldn't exist.

Pass by reference means you ultimately are pushing the address of a variable on the stack before the call, and pass by value means you push the value.  Since in assembly the pushes are explicit, there is no default convention.  For higher level languages (even C) when the function call syntax is translated into machine code, the decision has to be made which method to use.  The C designers chose pass by value as a default.  In contrast, FORTRAN, COBOL, and the other prevailing languages at the time (including PASCAL which C is most modeled after) did pass by reference.

I do agree that pass by value does more closely resemble what the CPU does.  Especially when you consider that you are most often pushing register values which may or may not be an address.  It is also possible to push the address of a memory location without first storing it in a register.

C could have been written with a pass by reference convention and that would not have had any impact on how the CPU works, but because it is pass by value in order to implement pass by reference you literally have to pass the reference as a value, e.g. the & operator which returns the address.

But you know all this, so I don't see what we are arguing about.  All I am saying is this particular complexity is due to C's pass by value convention, and wouldn't exist if C were pass by reference.


----- Original Message -----
From: "Benoît Minisini" <g4mba5 at gmail.com>

"Passing by reference" means nothing at the CPU level.

You can only send a pointer that points at a memory address.

Which C, as a low-level language, hopefully does not try to hide with 
syntactic sugar.

-- 
Benoît Minisini

----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----


More information about the User mailing list