|
The answers will most likely be garbage as the code refers to three different types in the same piece of memory. The float and long values will not have been initialised properly.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Your code is utterly broken. A more compiler-friendly one could be:
#include <iostream>
using namespace std;
union U
{
struct S
{
short int x;
short int y;
}s;
float f;
long l;
} u1;
int main()
{
u1.s.x=3;
u1.s.y=4;
cout << u1.f << endl;
cout << u1.l << endl;
}
Now let's have a look at the u1 memory layout (at least on my 32 bit machine):
ADDR 00 01 02 03
VALUE 03 00 04 00
where addresses are relative to &u1 .
Since the (my) machine is little endian, we have the following bit configuration
BYTES 0 0 0 4 0 0 0 3
BITS 0000 0000 0000 0100 0000 0000 0000 0011
That is, for the float member,
SIGN 0
EXP 0
MANTISSA 00001000000000000000011
That is a denormalized float (see here[^]) with value
(2^-5 + 2^-22 + 2^-23) * 2^-126 = 3.6735039242275079514265571025945 * 10^-40
that looks similar to the program output: 3.67346E-040
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]
|
|
|
|
|
Excellent answer.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thank you, Richard.
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]
|
|
|
|
|
While C.Pallini's response may be correct, there is no guarantee, as the internal format of float is not defined by the standard and therefore compiler-specific! There may even be compiler options to use a specific representation, so the result may change depending on those options.
Also the standard does not specify that long is a 32 bit type, only that it must be at least 32 bit. While I know of no compiler that does this*, any compiler is free to use more than 32 bits, especially when the OS is not 32 bit! If for instance long were a 64 bit type, the value of l would be 3*2^48+4*2^32 , which is a lot bigger than 3*2^16+4 in case of a 32 bit long type.
*compilers that support bigger than 32 bit integer types usually provide them by different names, such as 'long long ' or '__int64 ', rather than just 'long '
|
|
|
|
|
As you correctly note, the particular memory layout I considered is not assured (this is why I specified 'on my 32 bit', 'little endian' machine and so on). My aim was to give him a method for investigating such matter.
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]
|
|
|
|
|
Hello Friends
I am using vector and I used vector::iterator to iterate over the elements.
And after that I am using vector::reference = vector.back() to access last element.
Now,i want to assign all these refernce value to iterator one.
Any Ideas ?
Thanks & Regards
Yogesh
|
|
|
|
|
for (int i=1;i<vec.size();i++) vec[i] = vec[0];
?
|
|
|
|
|
You can't. The type of vector<T>::reference is T& , and has no reference to the original vector object, only to one element of type T .
The only way to assign an iterator is either through one of the methods of vector , or by assigning another iterator.
If you want an iterator to the last element, you can do this:
std::vector<int> myvector(5); std::vector::iterator last = myvector.end(); --last;
P.S.: after rereading your question I think I may have misinterpreted your question. If this isn't what you wanted and need more help, please clarify.
|
|
|
|
|
Thanks For your Answers.
I also proceed with the Stefan Method.
Thanks A Lot.
Regards
Yogesh
|
|
|
|
|
hi all,
i want to test comressed file or Archive in my MFC application.
i want its a valid zip file or not.
i have no idea from where i have to start.
please guide me and help me for this.
thanks in advance.
|
|
|
|
|
Use Google to find details on the different types of compressed files and their signatures.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
now how to open these files and decide these are valid archive or not.
|
|
|
|
|
I just explained what you need to do; what more information do you need?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
on signature basis i just found file is which type not that is valid or not.
so i want any class or function using the i can find the file is valid or not.
like test method in 7zip application.
|
|
|
|
|
Given the problem you are trying to resolve I would think you will have to write the function yourself. There are lots of resources on the internet concerned with compressed files that will help you.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
can provide any one out of this
thanks.
|
|
|
|
|
Le@rner wrote: i want its a valid zip file or not.
Are you using some sort of ZIP library or API?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
use the LiteZip and LiteUnZip article from code project.
LiteZip and LiteUnzip[^]
i am use its dll in my application.
|
|
|
|
|
So why not post your question to that article so the author will see it? Surely he has written some sort of "zip test" functionality to that library.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hello,
i googled a lot and and dont know what is the best way to messure the time that takes an execution of a function,is there some "stopwatch" in MFC?
Thanks
|
|
|
|
|
Just use QueryPerformanceCounterFrequency and QueryPerformanceCounter.
See here[^]
|
|
|
|
|
Hey,
Just to make sure i understood right
I query the count at the begining and at the end, then i devide it by the frequency and the result is the soconds?
Thanks
|
|
|
|
|
A thing to note: 'to measure' is the act of determining the value of a property. 'to mess (something up)' is somewhat synonym to 'meddle' or 'create chaos'. I'll assume that by 'messure' you mean the former, not the latter.
|
|
|
|
|
To 'meddle' with the 'value of a property': messure
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|