Re: Still confuse with return

1998-09-05 Thread Glynn Clements


James wrote:

 - 2) Returning a type other than the declared value for the return type:
 - for exaple, the function:
 - 
 - int foo()
 - {
 -float y;
 - 
 -return y;
 -  }
 - 
 - would generate an error because it's retuurning type float where an int is 
expected.
 -
 -This won't generate an error (unless your compiler is seriously
 -broken). The return value will be silently converted to an int.
 
 gcc -Wall would point out (and 'fix') this wouldn't it?

No. There's nothing that warrants a warning, or needs to be fixed.
Implicit casts between numeric types are perfectly valid.

-- 
Glynn Clements [EMAIL PROTECTED]



Global variables

1998-09-05 Thread Ravindra Jaju

Hi!
Please tell me how to use global variables!

I am using a program which in which I define a variable before the main
function so that the functions after it can access and change it.

But the changes I make to the global (??) variable aren't refrected in the
main part of the program.
I have tried the static identifier tag as well, but it doesn't work out.
Please help.

Thanx!

Regards,
Ravindra Jaju



Re: Global variables

1998-09-05 Thread Glynn Clements


Ravindra Jaju wrote:

 Please tell me how to use global variables!

At one time, I would have taken it for granted that a question such as
this had to be a joke. Nowadays I just wonder how long it's going to
be before people start posting to mailing lists with questions like
`How do I turn my computer on?'

-- 
Glynn Clements [EMAIL PROTECTED]



Re: Global variables

1998-09-05 Thread Marin D

As u havent included any example I would suppose the situation is as
follows:

///
int global;

void do_change(int x, int y)
{
  x = y;
  return;
}

int main()
{
...
do_change(global,100);
...
/* oops global is still unchanged = 0 */

}
/

Am I right? If so just change do_change to

void do_change(int* x, int y)
{
  *x = y;
  return;
}

and call it with

do_change(global,100);


...in the first example parameter X is passed by value (i.e. your function
works with a local copy of the actual object) so the global variable is
still unchanged after the execution

Regards,

Marin

-Original Message-
From: Ravindra Jaju [EMAIL PROTECTED]
To: Linux C Programming [EMAIL PROTECTED]
Date: 05 Ñåïòåìâðè 1998 ã. 20:37
Subject: Global variables


Hi!
Please tell me how to use global variables!

I am using a program which in which I define a variable before the main
function so that the functions after it can access and change it.

But the changes I make to the global (??) variable aren't refrected in the
main part of the program.
I have tried the static identifier tag as well, but it doesn't work out.
Please help.

Thanx!

Regards,
Ravindra Jaju