|
Perhaps that might work.
This does not explain though why it is allowed to say int test; in stdafx.h (which is included also in a lot of places)
Also I thought int test; is a declaration here. It would be illegal to write int test=3; .
I will give your suggestions a closer look, thanks for your quick replies!
-- modified at 7:47 Monday 6th March, 2006
Well, it works, thanks a lot!
|
|
|
|
|
jantimmerman wrote: This does not explain though why it is allowed to say int test; in stdafx.h (which is included also in a lot of places)
It's because you're using precompiled headers. VC++ only compiles the header once, and just references it in all the other files that include it. If you turn off precompiled headers, you'll have the same problem there.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I am experiencing problems after migrating to VS 2005 from VS 2003.
The application throws up an error saying mfc80u.dll cannot be loaded. According to MSDN this problem occurs because VS 2005 generates it's own embedded manifest file so if the project already consists a manifest file,there is some problem. They suggest converting the manifest to a header and using it as #pragma comment(linker,dependency).
Require help urgently on how to convert the manifest into .h and include it in preprocesor.
thanks in advance.
|
|
|
|
|
Hello Friends,
I have an a VC++ 6.0 SDI Application and wants to convert into a .Net application. Please help me out in this conversion, I am getting lots of errors as in the stdAfx.h file I had included iostream.h file, which is required?
Help me out.
Neelesh K J Jain.
|
|
|
|
|
you should include iostream.h likewise
<font color=blue>#include</font> <iostream>
and not
<font color=blue>#include</font> <iostream.h>
Nibu thomas
Software Developer
|
|
|
|
|
As someone else said, iostream.h is not standard C++. You also need to put using namespace std; at the top of the code, as standard C++ libraries use the std namespace.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi All,
Is there a fast way of checking to see if an int is a power of 2 (i.e. 2, 4, 8, 16, 1024)? I know the long way using a loop, but I was hoping for a simple way of doing this.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
|
Thanks
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
I think you will have problems when comparinf the floats, due to the precision.
|
|
|
|
|
true, but that was a starting point.
it would be better to use double at least, but still remains the precision problem.
|
|
|
|
|
2^3 = 8
but
floor(sqrt(8)) != sqrt(8)?
Steve
|
|
|
|
|
Modified version is still wrong - It will treat any integer as a power of 2.
Steve
|
|
|
|
|
i did not pretend to modified my post for a much working stuff...
|
|
|
|
|
if a number is a power of 2 than looking at the bits that composed that value must be all '0' but only one '1'.
So, if int is a 32 bit value, you can look for 31 '0' and 1 '1'.
But you need olso a loop! But it is quite fast.
Let me know if here is a faster bit function to count the ones/zeros
Bye
Have a nice code day
|
|
|
|
|
Yip, this was my way to begin with.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Read this function, it could be another start point!
This function that I wrote last year find the bigger long, greater than the input value, that is a power of 2.
And it is quite fast!
unsigned long Next2Power(unsigned long x){<br />
unsigned long y=1, x1=x;<br />
if(x==0) return 0;<br />
while(x1!=0){<br />
x1>>=1;<br />
y<<=1;<br />
}<br />
y>>=1;<br />
if(y!=x) y<<=1;<br />
return y;<br />
}
Have a nice code day
|
|
|
|
|
_Russell_ wrote: This function that I wrote last year find the bigger long, greater than the input value, that is a power of 2.
Why not just use log<sub>2</sub>() ?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Because my function is faster (I think) than log2().
But if I'm wrong let me know how have a faster function. And why.
thanks
Have a nice code day
|
|
|
|
|
_Russell_ wrote: ...let me know how have a faster function.
This one benchmarks faster than the one you've shown:
unsigned long Next2Power(unsigned long x)
{
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;
return x;
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hello RichardS,
Try this one.
double val = 0.0;
val = log10(y) / log10(2.0);
int val2 = int(val);
if (val == val2)
else
here 'y' is value u want to check for power of 2.
Best of luck
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
we are on a standard C++ forum, not managed/CLI...
|
|
|
|
|
Hello v2.0,
We are on visual C++ & my suggesion is not wrong for it.
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
Divyang Mithaiwala wrote: my suggesion is not wrong for it.
yes it is, it will not work on a MFC/Win32 project...
it is only for managed C++ (which is not for this forum, but for the C++/CLI forum instead)
|
|
|
|
|
Here logic is simple
y = value that want to check
x = find a value that is in power of 2
so,
2^x = y
log 2^x = log y
x log 2 = log y
x = log y /log 2
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|