??? 12/09/08 00:20 Read: times |
#160775 - Calling conv more depending on target than language Responding to: ???'s previous message |
No. Pascal can pass parameters by both value and reference.
C only passes by value. When you use a pointer, you pass the value of the pointer. And if you want to modify the pointer, then you have to pass the address of the pointer, i.e. the value of the address of the pointer. This need to always use a pointer (or array as they are mostly interchangeable) is one of the things that may confuse a programmer who don't have so much experience with C. C++ extends C by also supporting pass-by-reference. The caller need not know that a parameter is sent by reference (with the exception that it must be a parameter value that can be taken the address of). And inside the function, the code does not show that there is an indirection in all accesses to the parameter. You have basic differences that C normally sends the parameters from right to left, and Pascal from left to right. And in Pascal, the function normally cleans up any parameters while in C it is the caller who has to clean up any stack. This distinction is why C support varying number of parameters to a user-defined function - if you pass the wrong number of parameters, the same code will also be responsible for removing them. Both can pass in registers. It is up to the compiler vendor. But in reality, the calling models do not really translate to the real hardware. Most compilers vendors uses whatever calling model that fits the ABI of the OS. This makes sure that on application can call OS functions and OS libraries without problems. In the embedded world, you don't have any OS (or other programs) to care about. So the compiler vendor may choose any way that works. On the 8051, the calling methods are mostly controlled by the 8051 limitations and exremely little by the language. Pascal or C should be able to produce almost identical assembly code if the two compilers where developed by the same person (and one compiler wasn't the first attemt at learning). Code quality is more important to discuss when you decide between one C compiler or another. Or one Pascal compiler and another. Make your language selection based on knowledge, and availability of examples and other developers. And possibly political customer or company requirements about what language the important products should be written in. |