LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-08-2008, 09:41 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 461

Rep: Reputation: 31
returning different types of variables from a function


Hi all,
is it possible to return different types of variables from a single function. eg int floats etc?
 
Old 02-08-2008, 10:13 AM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: Kennesaw, GA
Distribution: Ubuntu
Posts: 8,502

Rep: Reputation: 110Reputation: 110
In what language? In C, you'd have to use a tagged union or something similar to overlap the values. C99 would permit an anonymous tagged union.
 
Old 02-08-2008, 11:49 AM   #3
knobby67
Member
 
Registered: Mar 2006
Posts: 461

Original Poster
Rep: Reputation: 31
Appologies yes C
 
Old 02-08-2008, 08:53 PM   #4
vpsville
LQ Newbie
 
Registered: Feb 2008
Location: Canada
Posts: 12

Rep: Reputation: 0
Quote:
Originally Posted by knobby67 View Post
Hi all,
is it possible to return different types of variables from a single function. eg int floats etc?
The usual method (in C) would be to pass a list of parameters to the function (called a procedure in this case). These would have to be pointers to variables so the modifications within the function stick, otherwise you'll be modifying copies of the variables instead.

These parameters can be any kind of variable, including structures.

For example:

int myProc(int *i, float *f)
{
i++;
f += 3.14;

return true;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl - returning array from a function rose_bud4201 Programming 6 07-13-2007 01:02 AM
C Enumerated Types / Function Pointer Errors Centinul Programming 8 11-07-2006 07:46 PM
problem with function returning pointers ***func() mlaich Programming 5 01-19-2006 09:17 PM
Using Bash Script for Exporting and Returning Environmental Variables Jicksta Programming 3 12-04-2004 04:14 PM
returning an array from a function.. javascript sonesay Programming 1 06-07-2004 05:28 AM


All times are GMT -5. The time now is 05:15 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration