Click here to Skip to main content
15,895,538 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: about change array length Pin
CPallini14-Dec-11 11:43
mveCPallini14-Dec-11 11:43 
AnswerRe: about change array length Pin
szpillka15-Dec-11 5:32
szpillka15-Dec-11 5:32 
QuestionA quastion in programming language desing' scope Pin
desatir731613-Dec-11 20:43
desatir731613-Dec-11 20:43 
AnswerRe: A quastion in programming language desing' scope Pin
Orjan Westin14-Dec-11 0:05
professionalOrjan Westin14-Dec-11 0:05 
GeneralRe: A quastion in programming language desing' scope Pin
David Crow14-Dec-11 3:32
David Crow14-Dec-11 3:32 
Questionwhat is the result(union & structure)? Pin
desatir731613-Dec-11 20:32
desatir731613-Dec-11 20:32 
AnswerRe: what is the result(union & structure)? Pin
Richard MacCutchan13-Dec-11 22:13
mveRichard MacCutchan13-Dec-11 22:13 
AnswerRe: what is the result(union & structure)? Pin
CPallini14-Dec-11 2:33
mveCPallini14-Dec-11 2:33 
Your code is utterly broken. A more compiler-friendly one could be:
C++
#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]

GeneralRe: what is the result(union & structure)? Pin
Richard MacCutchan14-Dec-11 2:40
mveRichard MacCutchan14-Dec-11 2:40 
GeneralRe: what is the result(union & structure)? Pin
CPallini14-Dec-11 2:42
mveCPallini14-Dec-11 2:42 
AnswerRe: what is the result(union & structure)? Pin
Stefan_Lang14-Dec-11 5:34
Stefan_Lang14-Dec-11 5:34 
GeneralRe: what is the result(union & structure)? Pin
CPallini15-Dec-11 10:10
mveCPallini15-Dec-11 10:10 
QuestionHow to Convert vector::reference to vector::iterator ? Pin
002comp13-Dec-11 20:21
002comp13-Dec-11 20:21 
AnswerRe: How to Convert vector::reference to vector::iterator ? Pin
Chris Losinger14-Dec-11 2:22
professionalChris Losinger14-Dec-11 2:22 
AnswerRe: How to Convert vector::reference to vector::iterator ? Pin
Stefan_Lang14-Dec-11 5:40
Stefan_Lang14-Dec-11 5:40 
GeneralRe: How to Convert vector::reference to vector::iterator ? Pin
002comp14-Dec-11 17:30
002comp14-Dec-11 17:30 
Questionhow to test a compressed file in MFC? Pin
Le@rner13-Dec-11 20:20
Le@rner13-Dec-11 20:20 
AnswerRe: how to test a compressed file in MFC? Pin
Richard MacCutchan13-Dec-11 22:09
mveRichard MacCutchan13-Dec-11 22:09 
GeneralRe: how to test a compressed file in MFC? Pin
Le@rner13-Dec-11 23:52
Le@rner13-Dec-11 23:52 
GeneralRe: how to test a compressed file in MFC? Pin
Richard MacCutchan14-Dec-11 0:08
mveRichard MacCutchan14-Dec-11 0:08 
GeneralRe: how to test a compressed file in MFC? Pin
Le@rner14-Dec-11 0:35
Le@rner14-Dec-11 0:35 
GeneralRe: how to test a compressed file in MFC? Pin
Richard MacCutchan14-Dec-11 0:38
mveRichard MacCutchan14-Dec-11 0:38 
GeneralRe: how to test a compressed file in MFC? Pin
Le@rner14-Dec-11 0:46
Le@rner14-Dec-11 0:46 
QuestionRe: how to test a compressed file in MFC? Pin
David Crow14-Dec-11 3:34
David Crow14-Dec-11 3:34 
AnswerRe: how to test a compressed file in MFC? Pin
Le@rner14-Dec-11 17:16
Le@rner14-Dec-11 17:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.