Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-08-2008, 09:41 AM   #1
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
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
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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
Registered: Mar 2006
Posts: 627

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

Rep: Reputation: 0
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)
f += 3.14;

return true;


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

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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:14 PM.

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