LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
  Search this Thread
Old 05-07-2009, 04:54 PM   #1
Shay
Member
 
Registered: Sep 2003
Posts: 77

Rep: Reputation: 15
What array is this C function expecting?


I want to use a function that starts out:
Code:
REAL some_func(some_array)
  REAL *some_array;
I'm trying to call this with:
Code:
float my_array[2];
my_array[0] = 1;
my_array[1] = 2;
some_func(my_array);
Doesn't work. some_array ends up filled with different numbers.
Any suggestions?

-Shay
 
Old 05-07-2009, 06:16 PM   #2
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
I think you may be mixing languages, perhaps... it isn't clear from your example.
REAL is a data type in most java implementations, but not c/c++.
Unless you have typedef'd it somewhere you should also be getting a host of other errors.

This should work:
Code:
#include <stdio.h>

float some_func(float *some_array);

int main(int argc, char **argv)
{
  float my_array[2];
  my_array[0] = 1.0;
  my_array[1] = 2.0;

  float val = some_func(my_array);

  printf("val=%f\n", val);
}

float some_func(float *some_array)
{
  return some_array[0] + some_array[1];
}

Last edited by raconteur; 05-07-2009 at 06:18 PM.
 
Old 05-07-2009, 06:52 PM   #3
rriggs
Member
 
Registered: Mar 2009
Location: Colorado, US
Distribution: Fedora 13, Fedora 14, RHEL6 Beta
Posts: 46

Rep: Reputation: 17
It looks like you are trying to use ancient C code. Hard to tell without more context.
 
Old 05-07-2009, 09:35 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Speaking of mixing langs (and you are doing numeric stuff), sounds like you're mixing FORTRAN with C. REAL is a type in FORTRAN.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash array to function rejeep Programming 5 11-27-2007 02:05 PM
Perl - returning array from a function rose_bud4201 Programming 6 07-13-2007 01:02 AM
Array structs - passed to function cdog Programming 4 02-02-2006 03:07 PM
sending pointer array to function marek Programming 4 04-15-2004 04:46 PM
c++ function & array question shaggy112 Programming 1 05-24-2001 10:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:41 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration