It is currently Sat, 26 Nov 2022 05:16:51 GMT



 
Author Message
 Initializing variables

Whoever told you this is mistaken.  The semantics are that the variable will
be allocated on the stack and initialized each time the function is entered.
It is therefore reentrant and thread-safe.  Just don't try to return a pointer
to it.

int *SomeFunction(void) {
    int counter=0;
... do something with it ...
    return &counter;    /* this would be a *bad thing* */

----
========================================
Richard Scranton - LDA Systems, Columbus
scra...@ix.netcom.com



 Tue, 13 Jul 1999 03:00:00 GMT   
 Initializing variables

yes.

By whom?



 Tue, 13 Jul 1999 03:00:00 GMT   
 Initializing variables

In article <5cb5d5$...@pulp.ucs.ualberta.ca>, nbeh...@ee.ualberta.ca (Nader
|> It seems to me that I can write:
|>     int counter = 0;
|> But I have been told that it is technically not allowed!

Many of the examples in K&R initialize variables.  If an expert
told you otherwise, I assume that you misunderstood them.

--
Ken Lee, ken...@rahul.net, http://www.rahul.net/kenton/index.shtml



 Tue, 13 Jul 1999 03:00:00 GMT   
 Initializing variables

Hi all,

I would like to know if there is anything wrong with this initialization
and declaration:

void SomeFunction(void) {

    int counter = 0;       /*  <-------  Is this legal? */

    ...

Is this illegal in C. On page 40 of K&R Edition2 it says:
"An explicitly initialized automatic variable is initialized
each time the function or block it is in is entered; the initializer
may be any expression."

It seems to me that I can write:
    int counter = 0;
But I have been told that it is technically not allowed!

Thank you in Advance,
Sincerely,
Nader

--
---------------------------------------------------------------------
|                                                                   |
| Nader T. Behzad                                                   |
| e-mail: nbeh...@ee.ualberta.ca                                    |
| WWW: http://www.ee.ualberta.ca/~nbehzad                           |
|                                                                   |
|===================================================================|
|                                                                   |
| "Whatever you do will be insignificant, but it is very            |
|  important that you do it." --Mahatma Gandhi                      |
|                                                                   |
---------------------------------------------------------------------



 Tue, 13 Jul 1999 03:00:00 GMT   
 
   [ 4 post ] 

Similar Threads

1. How do I read a ini file to initialize variables

2. initialize the global variables in .so files

3. Initializing ksh variables

4. initializing a variable and simultaneously keeping terminal output

5. initializing a global variable at apache startup

6. How to initialize complex per-cpu variables?

7. New to Linux: how are dev variables initialized?

8. Setting variables in a variable array of null variables

9. Variable substitution within a variable name

10. file contents into variable, or global variable from shell script


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software