Hello All,
I am looking for some way to delay the global variable initilization.
To make myself more clear, here is a simple example:
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++
#include <stdio.h>
int glob1, glob2;
struct test
{
int a;
int b;
};
struct test c_CF = { glob1,glob2};
int main ()
{
glob1=100;
glob2 = 200;
printf ("%d %d \n",c_CF.a, c_CF.b);
}
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++
output: 0 0
++++++++++++++++++++++++++++++++++++++++++++++++++ +++
Is there a way I can delay the global variable initilization until the
moment it is referred for the first time.
Thanks and Regards
-Vallabha 5 1706 vs*********@gmail.com <vs*********@gmail.com> a écrit*: I am looking for some way to delay the global variable initilization.
I think you can not: you need to use another mechanism. To make myself more clear, here is a simple example: ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++
int glob1, glob2;
struct test {
int* a;
int* b; };
struct test c_CF = { &glob1,&glob2}; int main () { glob1=100; glob2 = 200;
printf ("%d %d \n",c_CF->a, c_CF->b); }
Is this solution relevant for your problem ?
Marc Boyer
Marc Boyer wrote: vs*********@gmail.com <vs*********@gmail.com> a écrit :
I am looking for some way to delay the global variable initilization.
I think you can not: you need to use another mechanism.
To make myself more clear, here is a simple example: ++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++
int glob1, glob2;
struct test {
int* a; int* b;
};
struct test c_CF = { &glob1,&glob2};
int main () { glob1=100; glob2 = 200;
printf ("%d %d \n",c_CF->a, c_CF->b);
ITYM printf ("%d %d \n", *(c_CF.a), *(c_CF.b)); }
Is this solution relevant for your problem ?
Marc Boyer vs*********@gmail.com wrote:
[...] #include <stdio.h>
int glob1, glob2;
struct test { int a; int b; };
struct test c_CF = { glob1,glob2};
[...]
Is this even legal? How can you initialize a struct to the values stored
in other variables?
It fails on my system with "initlaizer is not a constant" errors.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
"Kenneth Brody" <ke******@spamcop.net> wrote in message
news:43***************@spamcop.net... vs*********@gmail.com wrote: [...] #include <stdio.h>
int glob1, glob2;
struct test { int a; int b; };
struct test c_CF = { glob1,glob2}; [...]
Is this even legal?
Not at file scope. But it's OK at block scope if
the object is 'auto' (i.e. not 'static').
How can you initialize a struct to the values stored in other variables?
As above, given that it's 'auto'. It fails on my system with "initlaizer is not a constant" errors.
It should.
-Mike vs*********@gmail.com wrote: Hello All,
I am looking for some way to delay the global variable initilization.
To make myself more clear, here is a simple example: ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++ #include <stdio.h>
int glob1, glob2;
struct test { int a; int b; };
struct test c_CF = { glob1,glob2};
int main () { glob1=100; glob2 = 200; printf ("%d %d \n",c_CF.a, c_CF.b); } ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++ output: 0 0 ++++++++++++++++++++++++++++++++++++++++++++++++++ +++
Is there a way I can delay the global variable initilization until the moment it is referred for the first time.
No.
Objects with static duration, like globals,
are initialized before main is executed.
They can only be initialized with constant expressions.
--
pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Hitillambeau |
last post by:
Hi guys,
As I am new to Python, i was wondering how to declare and use global
variables. Suppose i have the following structure in the same module (same
file):
def foo:
<instructions>...
|
by: M.L. |
last post by:
Hi NG,
I hope someone in here is able to help me in this matter. The problem:
I have created a Javascript drop-down menu which expands when moving the
mouse into a tablecell (calls my Expand()...
|
by: Don Lancaster |
last post by:
I am conjuring up some simple JavaScript animation routies that work
entirely WITHIN Acrobat .PDF files.
They work very well but they are waay too fast! And are also CPU speed
dependent.
I...
|
by: Roger Withnell |
last post by:
I have tried using setTimeout to delay the execution of a function with:
setTimeout('function()', ms)
This works, but if the function has parameters:
setTimeout('function(p1, p2, p3)', ms)
...
|
by: lucifer |
last post by:
hi
i need to insert delay in my program what function should i use
the old delay is not supported by the VC6
| |
by: Ed Jensen |
last post by:
I'm having a vexing problem with global variables in Python. Please
consider the following Python code:
#! /usr/bin/env python
def tiny():
bar =
for tmp in foo:
bar.append(tmp)
foo = bar
|
by: weaknessforcats |
last post by:
C++: The Case Against Global Variables
Summary
This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
|
by: istillshine |
last post by:
When I control if I print messages, I usually use a global variable
"int silent". When I set "-silent" flag in my command line
parameters, I set silent = 1 in my main.c.
I have many functions...
|
by: sheldonlg |
last post by:
I came across a problem and googling for an answer didn't help.
What I want to do is run an AJAX script that sets a hidden variable on
the form. I call the AJAX script from a javascript...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |