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 1666 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: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |