Re:tss on stack???
Posted: Mon Sep 12, 2005 12:21 am
Hi,
With 2 return values:
Or with a hidden return value, where "errno" is also returned behind the callers back (which for most older C libraries, causes re-entrancy problems for anything multi-threaded):
Of course usually the single return value is mangled to serve dual purposes. A typical example of this is "malloc()", where instead of returning a status code and an address it combines both. This works, but means that returning a reason why the function failed is impossible. Did it fail because memory ran out, or because the heap has been corrupted, or because I accidentallty asked it to allocate 3.5 GB? Sorry - no way to tell.
The instances where multiple return values are used depends on the programmer and the language. For a programmer who is conditioned to work within the limitations of a HLL language, it may be rare.
For my assembly code (and code designed for or written in assembly) it happens quite frequently and results in better code (from the CPU's perspective). For examples of functions where the design was not limited by broken compilers, see the BIOS functions (where returning multiple values is very common).
Cheers,
Brendan
For IRQ handlers this is indeed the case. Unfortunately IRQ handler's are not (or at least should not) be the only place where a task switch may occur. Any kernel function that causes a task to be blocked (wait_for_message(), getchar(), sleep(), fopen(), etc) also causes a task switch. This implies that the entire kernel API is also effected.AR wrote:Why exactly do you need more than one return value? I usually use "void" as the return value for the C function to the interrupt stub, I don't see what exactly you're referring to.
I guess you're right - functional languages may have been built on the mathematical principles of an algebraic equation, which are inappropriate, unnecessary and just plain broken. The ugly hacks that have evolved to get around this limitation seem to agree with me. Consider 2 simple C library functions:AR wrote:I believe the one return value is built on the mathematical principles of an algebraic equation. eg: m = f(b), m = a + 3b + 2. In maths there is always only one result from an equation, all languages that I know which are higher than assembly seem to be built on this principle which basically means that any and all algorithms can be broken down to components that will only require 1 return value. Of course in computers there are more than just numbers (strings, images) but the instances where multiple return values are absolutely necessary don't come around that often.
With 2 return values:
Code: Select all
long int strtol (const char *restrict string, char **restrict tailptr, int base);
Code: Select all
FILE * fopen (const char *filename, const char *opentype);
The instances where multiple return values are used depends on the programmer and the language. For a programmer who is conditioned to work within the limitations of a HLL language, it may be rare.
For my assembly code (and code designed for or written in assembly) it happens quite frequently and results in better code (from the CPU's perspective). For examples of functions where the design was not limited by broken compilers, see the BIOS functions (where returning multiple values is very common).
Cheers,
Brendan