From: colin AT bird DOT fu DOT is DOT saga-u DOT ac DOT jp (Colin Peters) Subject: Fw: return several types in a function (NBY) 25 Jan 1998 19:30:23 -0800 Message-ID: <01bd2a07$a6dbc400$fa173185.cygnus.gnu-win32@gbird0.fu.is.saga-u.ac.jp> Reply-To: "Colin Peters" Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit To: "GNU-Win32" 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 To: Anonymous Date: Monday, January 26, 1998 11:44 AM Subject: Re: return several types in a function >From: Anonymous >To: gnu-win32 AT cygnus DOT 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 AT cygnus DOT com" with one line of text: "help".