Re: Simple signal/event question
- From: "Peter Garner" <peter garner toward com>
- To: gtk-list redhat com
- Subject: Re: Simple signal/event question
- Date: Mon, 13 Dec 99 02:01:08 -0500
Hi Havoc, Hi All! :-)
>The return value has to be stored in memory somewhere; if the
>compiler thinks there is no return value when invoking the
>function pointer it doesn't have to make that memory. But if the
>function being invoked has a return value it will put the return
>value there anyway.
I was going to take this to private email with Havoc, but I
decided it MIGHT be of interest to the list. The reason being is
that some gtk signal CALLBACK can return values and others may
not. In fact one of the MOST powerful features of GTK is the
almost infinite variety of signatures that one can use with
callback functions. Thus we all might run into a situation where
we have a mismatch with the return type.
Merely calling a function with that returns a value when the
compiler thinks it returns void will NOT cause a problem on ANY
machine/compiler combination of which I am aware. C/C++
compilers generally just place the return value in a register and
leave it at that. On the ix86 series, calling "return 0" merely
loads EAX with 0. In the case of structures, things are a little
more complicated, but the same principle applies.
All that matters is what you DO with the return
value. If your function returns void, and the caller THINKS a
value is being returned, and attempts to use the return value,
it will use whatever random garbage is in the accumulator (EAX)
register. If the caller THINKS the function returns void (which
is what we were originally discussing) I cannot think of ANY
situation where this would cause problems since the caller will
simply ignore the [valid] data in EAX. Of course if you are
returning the address of some malloced structure [in EAX] and
ignore that, you will get a memory leak, but that is ENTIRELY
another story! ;-)
In summary, substituting a non void function in place of a
function that returns void should not cause a problem. I
apologise to anyone who thinks this OTO for this list. However,
given the almost unlimited flexibility of gtk signals, this may
become an issue for some of us. In addition, understanding how
return values work is essential for calling and
interfacing assembler routines from C/C++. In otherwords to
return a value to a C caller from an assembly routine, simply
load EAX with the value before returning from the function.
(And of course, if you are using C++, do not forget to declare
the asm routine as extern "C"! ;-)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]