This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Fw: return several types in a function (NBY)


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.

-- Colin Peters -- colin at fu.is.saga-u.ac.jp
-- Saga University Dept. of Information Science
-- http://www.fu.is.saga-u.ac.jp/~colin
-- http://www.geocities.com/Tokyo/Towers/6162

-----Original Message-----
From: Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
To: Anonymous <anon@anon.efga.org>
Date: Monday, January 26, 1998 11:44 AM
Subject: Re: return several types in a function


>From: Anonymous <anon@anon.efga.org>
>To: gnu-win32@cygnus.com <gnu-win32@cygnus.com>
>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[10].
>
>
>If I understand correctly you want to do something like
>
> int, char[10] 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[10];
>
>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
function
>whether it modifies it's arguments or not.
>
>Another solution is to use structures:
>
>  struct bar
>  {
>    int x;
>    char y[10];
>  };
>
>  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
you
>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.
>
>Good luck,
>Colin.
>
>-- Colin Peters -- colin at fu.is.saga-u.ac.jp
>-- Saga University Dept. of Information Science
>-- http://www.fu.is.saga-u.ac.jp/~colin
>-- http://www.geocities.com/Tokyo/Towers/6162
>
>

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]