avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Cpp Question


From: E. Weddington
Subject: Re: [avr-gcc-list] Cpp Question
Date: Thu, 4 Sep 2003 15:06:26 GMT

> Hi!
> 
> I was recently more involved in Pascal, now I'm in C :)
> 
> I'm trying to program a function which returns values as 
parameters:
> 
> void foo(int a, int b, float c)
> {
> b++;
> c=sqrt(a+b)
> }
> 
> but it does't work
> In Pascal it could be done if it is written as
> 
> procedure foo(var a,b:integer;var c:real)
> begin
> b=b+1;
> c=sqrt(a+b);
> end;
> 
> and voila, you get after foo(a,b,c), b incremented and 
> c as stated :)
> but it won't work if the procedure is as that:
> 
> procedure foo(a,b:integer; c:real)
> begin
> b=b+1;
> c=sqrt(a+b);
> end;
> 
> soo after call to that with foo(a,b,c), original a b & c
> won't change. how to do this in c?
> 

You pass an address of the variable to the function, and 
the function assigns the value to the dereferenced address.

void foo(int a, int b, float &c)
{
  b++;
  *c=sqrt(a+b)
}

You can also have it return the value:

float foo(int a, int b)
{
  b++;
  return(sqrt(a+b));
}

This really has nothing to do with the AVR, it's a general 
C question. It would be better to post this to the 
comp.lang.c newsgroup, or find a good book or reference on 
the C
language.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]