delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/12/00:53:29

From: Nate Eldredge <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Variable Passing
Date: Mon, 11 Oct 1999 14:41:32 -0700
Organization: Harvey Mudd College
Lines: 50
Message-ID: <3802598C.DA873BD7@hmc.edu>
References: <7ttdh9$plb$1 AT gxsn DOT com>
NNTP-Posting-Host: mercury.st.hmc.edu
Mime-Version: 1.0
X-Trace: nntp1.interworld.net 939678137 69728 134.173.45.219 (11 Oct 1999 21:42:17 GMT)
X-Complaints-To: usenet AT nntp1 DOT interworld DOT net
NNTP-Posting-Date: 11 Oct 1999 21:42:17 GMT
X-Mailer: Mozilla 4.61 [en] (X11; U; Linux 2.2.13pre12 i586)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Anthony Graham wrote:
> 
> I thought i had all the basics of C then I got stumped again.....
> 
> How do you pass variables between procedures? (Without making a global
> variable)
> 
> Here's the senario....
> 
> int caller()
> {
> float myvalue;
> 
> myvalue=1;
> called(myvalue);
> 
> }
> 
> void called(float passedvalue)
> {
> .....
> 
> }
> 
> This is a v. short example. If i debug my code i see that the value to be
> passed is right but the "passedvalue" in the second loop is:
> any of the following....
>         INF(inate)
>         x.xxxxE-xx
>         ....
>         and anything but one!!!
> 
> What am i doing wrong?

You need to have a prototype for `called' before you try to call it. 
So, for instance, add something like the following at the top of your
program:

void called(float passedvalue);

If you don't, the compiler makes assumptions about the types of
arguments the function takes, which in this case are wrong.

Note that if you compile with the -Wall option, the compiler will warn
you about this ("implicit declaration" means it's going to use default
assumptions, which is generally not good).
-- 

Nate Eldredge
neldredge AT hmc DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019