Re: a question of style
- From: Artie Gold <artiegold@xxxxxxxxxxxxx>
- Date: Tue, 28 Feb 2006 13:29:08 -0600
questions? wrote:
I am curious about whether I should do thisWell since option 2 is not an option at all (arrays are not a first class type in C, so an array cannot be a return value), you're left with option 1.
say I want to calculate dot product of two matrix(4X4,fixed)
I do two ways
1)
void dot_product(double A[4][4] , double B[4][4], double result[4][4]){
blah blah
}
my results are automatically given back in the matrix result[4][4]
or
2)
double [4][4] dot_product(double A[4][4],double B[4][4]){
double result[4][4];
blah blah
return result;
}
for the second type, result is local variable and will be released
after function call, Will the program have problem to access?
Are there better and neat way to this problem?
Thanks
The other option would be to wrap your array in a struct and return *that*, but that would depend upon how you plan on using this code...
BTW - explicitly mentioning the first dimension of a passed array is superfluous; i.e. `double A[][4]' and `double A[4][4]' -- or for that matter double A[400][4] -- mean the same thing.
HTH,
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
.
- Follow-Ups:
- Re: a question of style
- From: questions?
- Re: a question of style
- References:
- a question of style
- From: questions?
- a question of style
- Prev by Date: Launch of User Interface Community
- Next by Date: Re: Help in c pointers
- Previous by thread: a question of style
- Next by thread: Re: a question of style
- Index(es):
Relevant Pages
|