Fw: return several types in a function (NBY)
Sun Jan 25 19:28:00 GMT 1998
Since this message was posted via an anonymous remailer it appears I
cannot reply to the author
directly. Thus I'm forwarding to the mailing list (apologies to all).
-- Colin Peters -- colin at fu.is.saga-u.ac.jp
-- Saga University Dept. of Information Science
From: Colin Peters <firstname.lastname@example.org>
To: Anonymous <email@example.com>
Date: Monday, January 26, 1998 11:44 AM
Subject: Re: return several types in a function
>From: Anonymous <firstname.lastname@example.org>
>To: email@example.com <firstname.lastname@example.org>
>Date: Sunday, January 25, 1998 5:27 PM
>Subject: return several types in a function
>>I know this is a bit off-topic, but I don't know
>>where to look for help.
>Well, it's actually way, way, waaay off topic, but anyway... :)
>>What do I write to get a function to return more
>>than one thing and type, lets say in a DLL?
>>eg foo() should return an int and a char.
>If I understand correctly you want to do something like
> int, char foo();
>As a function prototype. The problem with this is not DLL's or GCC, but
>the C/C++ language itself. This is simply not possible, a function can
>only 'return' a single value. But before you throw your hands up in
>dispair, it is possible to make a function that modifies it's arguments
>(though you should be very, very careful). For example you could do
>something like this:
> int foo (char* pointer_to_char); /* Function prototype */
> int x;
> char y;
>x = foo (y);
>Your foo function could then modify the contents of the char buffer y,
>since it is being passed a *pointer* to the buffer. As I said, this is
>sometimes confusing, because you can't see just by looking at the
>whether it modifies it's arguments or not.
>Another solution is to use structures:
> struct bar
> int x;
> char y;
> struct bar foo();
> struct bar z;
> z = foo();
>Though this is not such a elegant solution from the point of view of the
>actual code run by the machine (and it requires your compiler know how to
>return structures from functions, which is not always true). I suggest
>grab a copy of Kernighan and Ritchie "The C Programming Language" and/or
>another C programming book and read the chapter(s) on pointers and
>pointers as arguments to functions.
>-- Colin Peters -- colin at fu.is.saga-u.ac.jp
>-- Saga University Dept. of Information Science
For help on using this list (especially unsubscribing), send a message to
"email@example.com" with one line of text: "help".
More information about the Cygwin