|
Global variables must be defined in a .cpp file. You may initialize them wherever you want.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thank you for all of you.
Anyway Itried to make initialization in Initinstance and the project's constructor but its not working always give me an unresolved variable.
Its work fine when Iam access my variables and functions via theApp, but I should include the "ProjectName.h" in each function i want to use the variable there not like the extern int x(for example). So I am not sure if these variables will reserved its values during the cycle of system.
anyway I will test it. and thank you again for all of you.
Regards,
|
|
|
|
|
Thank you for all of you.
Anyway Itried to make initialization in Initinstance and the project's constructor but its not working always give me an unresolved variable.
Its work fine when Iam access my variables and functions via theApp, but I should include the "ProjectName.h" in each function i want to use the variable there not like the extern int x(for example). So I am not sure if these variables will reserved its values during the cycle of system.
anyway I will test it. and thank you again for all of you.
Regards,
|
|
|
|
|
I know that there's a method,
C++
UINT MsiInstallProduct(
__in LPCTSTR szPackagePath,
__in LPCTSTR szCommandLine
);
However, it needs a package path, how can i get it by product code?
Thanks!
|
|
|
|
|
when I updating excel file using odbc driver I got the following exceptions frequently When I click on any cell
Key violation.
[Microsoft][ODBC Excel Driver] The connection for viewing your linked Microsoft Excel worksheet was lost.
Key violation.
[Microsoft][ODBC Excel Driver] The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened
General SQL error.
exclusively by another user, or you need permission to view its data.
how can I prevent to avoid these exceptions
Trioum
|
|
|
|
|
You can run your program under the debugger to understand the nature of these exceptions and then fix your code.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
How Can I fix the following error
Trioum
|
|
|
|
|
Debug it. I won't be replying any further on this thread.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
in the name of god
hello
when we declare a variable in c++ as :
int x;
int x1=98;
then initialize it with a value.
how we can know that a variable has been initialized or no?is there any way (compiler can or ...)to distinguish between initialized variable and non-ini...
that we dont know the value of them.
valhamdolelah.
|
|
|
|
|
nope.
(don't take my word for it)
in DEBUG more, variable _can_ be initialized to zero (or some other default patterns) as an aid for internal debugging , but in RELEASE, they are not (for performance issues).
When compiling, I would assume the compiler is just checking if the variable was assigned something.
This signature was proudly tested on animals.
|
|
|
|
|
so how compiler knows it?
|
|
|
|
|
it could checks syntactically if the variable is on the left-hand side of an '=', of if syntactically if follows the syntax of an initializer...
for example :
int i;
i = 0;
or
int i(123);
or
class Tata
{
Tata() : m_i(123){};
int m_i;
};
Or there might be other more advanced compiler tricks to keep track of variable assignments...
This signature was proudly tested on animals.
|
|
|
|
|
in the name of god
thanks Maximilien.
i don't know it up to now.
i have also another question :you said that when we use = compiler knows that a variable is initialized so if it save any data for this?any data to know which variables are initialized if yes where?
thanks.
valhamdolelah.
|
|
|
|
|
khomeyni wrote: i don't know it up to now.
Don't know what?
khomeyni wrote: i have also another question :you said that when we use = compiler knows that a variable is initialized so if it save any data for this?any data to know which variables are initialized if yes where?
The information you are after is not available via code. It's something that the compiler handles internally.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i don't care about = ,() , ...
thanks.but indeed i want to know more ,but as it seem it is deep because of compilers.
thanks.
valhamdolelah.
|
|
|
|
|
Easy.
You created the variable, so you know if it's initialized or not. Unless you can't remember 
|
|
|
|
|
khomeyni wrote: how we can know that a variable has been initialized or no?
Looking at the code?
Ah, and the compiler warns about uninitialized variables.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thanks but:
suppose i created a variable x:int x; and then during program i dont use it and at last i want to know if it is initialized or no?for example if a condition occured then it would be initialized else ... and i dont know anything about this condition. i can use some idea as initializing it by infinite value but i want to know how to compiler do it? or is another way for?
valhamdolelah.
|
|
|
|
|
You should initialize a variable as soon as possible in your program.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
If no '=' has been encountered for a given variable during the token-parsing phase, it is assumed to be uninitialized. This is covered in compiler classes, and books such as the dragon book.
Keep in mind, though, all variables will have a value regardless of what that value is or where it came from.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hello
how it saves that a variable is initialized or no.does it saves any data(where?)?or compiler uses a special method?
valhamdolelah.
|
|
|
|
|
This is not a basic programming subject, and certainly does not belong in the C/C++ forum. Unless you've written a compiler/parser, or have studied the subject, any answer that you are provided will not make any sense.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Inner details of compilers are secret!
On the serious side:
inner details of compilers are secret!
If you are still there, consider that compiler's developers may freely choose the implementation details, provided they fullfill the language specification requirements. Hence different compilers may use different strategies to deal with the same problem.
If you are really interested in compiler inner mechanisms, I would suggest to start with some introductory material as, for instance, the excellent classic Wirth's "Compiler Construction", freely available (for instance here [^]).
As further reading, you may consider Hanson & Fraser's book "A Retargetable C Compiler: Design and Implementation" (see [^]): since lcc is a real compiler and its sourc code is available, you may have a look at it (well, gcc source code too is available...If you are going to examine it, good luck!).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
How about this. Use a boolean along with the integer. for example:
int x;
bool xIsInitialized = false;
And then, when you do start assigning some value to x, update the boolean to true.
I think this is a big waste of time though. You should always have it initialized, possibly to -1 or 0 to show that it hasn't been assigned to yet.
|
|
|
|
|
voted you down...
1- bad programming practice.
2- twice the danger of doing something stupid .. (change one and forget to change the other)
This signature was proudly tested on animals.
|
|
|
|