Array Variable initialization
-
CPallini wrote:
00401003 xor eax,eax
Look two lines up from this one and you should find:
rep stosd
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
No luck (there isn't such insruction). On the other hand, the output of this program [^] confirms my assumption. See also Sandip's post [^]. I should admit I was very surprised by such a behaviour. :)
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] -
SandipG :) wrote:
Same output with Visual C++ 6.0
Visual C++ is not what a decent programmer call a standard compliant compiler, Sir !
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
No luck (there isn't such insruction). On the other hand, the output of this program [^] confirms my assumption. See also Sandip's post [^]. I should admit I was very surprised by such a behaviour. :)
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]and what about {0} instead of {7}, and in Release Mode, not in Debug Mode ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
and what about {0} instead of {7}, and in Release Mode, not in Debug Mode ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
See my added remark here [^]. BTW my tests were of course performed both in
Debug
and theRelease
mode. ;P :)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] -
and what about {0} instead of {7}, and in Release Mode, not in Debug Mode ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
...and what about {0} instead of {7}...
0
works fine.toxcct wrote:
...and in Release Mode, not in Debug Mode ?
Same results for both
0
and7
. This is why I only do it when setting things to0
. I usememset()
otherwise."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
SandipG :) wrote:
Same output with Visual C++ 6.0
Visual C++ is not what a decent programmer call a standard compliant compiler, Sir !
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
IMHO such a discrepancy would be too gross, even for
VC6
. :)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] -
IMHO such a discrepancy would be too gross, even for
VC6
. :)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]yes, probably, but it's not *THE* compiler to test the standard ! ;) ;P
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
toxcct wrote:
...and what about {0} instead of {7}...
0
works fine.toxcct wrote:
...and in Release Mode, not in Debug Mode ?
Same results for both
0
and7
. This is why I only do it when setting things to0
. I usememset()
otherwise."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
DavidCrow wrote:
0 works fine.
It is just a side-effect of default (int) initialization: you're actually initializing only the first array item. Try the following code:
#include <iostream>
using namespace std;struct MyStruct
{
MyStruct():_i(-1), _j(0),_k(-1){ }
MyStruct(int a):_i(a), _j(a), _k(a){ }
int _i,_j,_k;
};void main()
{
int i;
MyStruct a[5] = {0};
for (i=0; i<5; i++)
{
cout << i << ") {" << a[i]._i << ", " << a[i]._j <<", " << a[i]._k << "}" << endl;
}
}DavidCrow wrote:
This is why I only do it when setting things to 0. I use memset() otherwise.
The above is a wise approach. :)
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] -
DavidCrow wrote:
0 works fine.
It is just a side-effect of default (int) initialization: you're actually initializing only the first array item. Try the following code:
#include <iostream>
using namespace std;struct MyStruct
{
MyStruct():_i(-1), _j(0),_k(-1){ }
MyStruct(int a):_i(a), _j(a), _k(a){ }
int _i,_j,_k;
};void main()
{
int i;
MyStruct a[5] = {0};
for (i=0; i<5; i++)
{
cout << i << ") {" << a[i]._i << ", " << a[i]._j <<", " << a[i]._k << "}" << endl;
}
}DavidCrow wrote:
This is why I only do it when setting things to 0. I use memset() otherwise.
The above is a wise approach. :)
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]For structs, I'd use
memset()
. I only use0
forPOD
types."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
For structs, I'd use
memset()
. I only use0
forPOD
types."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
DavidCrow wrote:
For structs, I'd use memset(). I only use 0 for POD types.
That's good. :)
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]