Click here to Skip to main content
15,899,025 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to build bitmaps from the scratch? Pin
Antony M Kancidrowski11-Aug-04 3:01
Antony M Kancidrowski11-Aug-04 3:01 
GeneralRe: How to build bitmaps from the scratch? Pin
Anonymous11-Aug-04 7:47
Anonymous11-Aug-04 7:47 
GeneralSDI Different Views Pin
Rassul Yunussov10-Aug-04 22:51
Rassul Yunussov10-Aug-04 22:51 
GeneralRe: SDI Different Views Pin
Michael P Butler10-Aug-04 23:37
Michael P Butler10-Aug-04 23:37 
GeneralRe: SDI Different Views Pin
Joel Holdsworth10-Aug-04 23:43
Joel Holdsworth10-Aug-04 23:43 
GeneralLists of a class : where to put a typedef Pin
Jerome Conus10-Aug-04 22:50
Jerome Conus10-Aug-04 22:50 
GeneralRe: Lists of a class : where to put a typedef Pin
Antony M Kancidrowski11-Aug-04 0:04
Antony M Kancidrowski11-Aug-04 0:04 
GeneralBits Fields - How to Use them Pin
sweep12310-Aug-04 22:24
sweep12310-Aug-04 22:24 
I have been trying to define a structure and use it with a union, but the bit fields seem to cause the structure to be bigger than I expected.

e.g. ( 4 x 4 bit fileds + 2 float fields + short = 11 bytes)
But what I get is 28 bytes.

// Data1	w03_second_10_s_;<br />
typedef struct <br />
{<br />
	unsigned	 data 	:	4	;	<br />
}W03_SECOND_10_S_;<br />
<br />
// Data2	w03_second_1_s_;<br />
typedef struct <br />
{<br />
	unsigned	 data 	:	4	;	<br />
}W03_SECOND_1_S_;<br />
<br />
// Data3	w03_second_0_1_s_;<br />
typedef struct <br />
{<br />
	unsigned	 data 	:	4	;	<br />
}W03_SECOND_0_1_S_;<br />
<br />
// Data4	w03_second_0_01_s_;<br />
typedef struct <br />
{<br />
	unsigned	 data 	:	4	;	<br />
}W03_SECOND_0_01_S_;<br />
<br />
// Data5	w05_price;<br />
typedef struct <br />
{<br />
	float		data; <br />
}W05_PRICE;<br />
<br />
// Data6	w07_netCost;<br />
typedef struct <br />
{<br />
	float		data; <br />
}W07_NETCOST;<br />
<br />
// Data7	w08_index;<br />
typedef struct <br />
{<br />
	unsigned short		data; <br />
}W08_INDEX;<br />
// All the fields into a sigle structure<br />
typedef struct{<br />
W03_SECOND_10_S_	w03_second_10_s_;<br />
W03_SECOND_1_S_		w03_second_1_s_;<br />
W03_SECOND_0_1_S_	w03_second_0_1_s_;<br />
W03_SECOND_0_01_S_	w03_second_0_01_s_;<br />
W05_PRICE			w05_price;<br />
W07_NETCOST			w07_netCost;<br />
W08_INDEX			w08_index;<br />
}TEST1_10;


// Form a union between the message structure and a buffer<br />
union<br />
{<br />
	TEST1_10			message_data;		// I expect this to be = 14 bytes<br />
	unsigned short		buffer[32];			// Max buffer size<br />
}messageStructData;<br />
<br />
int sizeStruct = sizeof(messageStructData);

The size if 64 bytes, but the size of the TEST1_10 structure is 28 bytes (not 11 bytes)so each field of 4 bits is taking up 4 bytes
TEST1_10			message_data1;<br />
int sizeStruct1 = sizeof(message_data1);

sizeStruct1 = 28 bytes.

The short is being padded to 4 bytes as is each 4 bit field.

Is it possible to map bit fields onto a structure and then a union in C++.
GeneralRe: Bits Fields - How to Use them Pin
Antony M Kancidrowski10-Aug-04 23:45
Antony M Kancidrowski10-Aug-04 23:45 
GeneralRe: Bits Fields - How to Use them Pin
sweep12311-Aug-04 1:24
sweep12311-Aug-04 1:24 
GeneralRe: Bits Fields - How to Use them Pin
Antony M Kancidrowski11-Aug-04 2:03
Antony M Kancidrowski11-Aug-04 2:03 
GeneralRe: Bits Fields - How to Use them Pin
David Crow11-Aug-04 5:25
David Crow11-Aug-04 5:25 
GeneralRe: Bits Fields - How to Use them Pin
sweep12311-Aug-04 6:12
sweep12311-Aug-04 6:12 
GeneralRe: Bits Fields - How to Use them Pin
David Crow11-Aug-04 7:23
David Crow11-Aug-04 7:23 
GeneralRe: Bits Fields - How to Use them Pin
sweep12311-Aug-04 21:58
sweep12311-Aug-04 21:58 
GeneralRe: Bits Fields - How to Use them Pin
David Crow12-Aug-04 2:58
David Crow12-Aug-04 2:58 
GeneralRe: Bits Fields - How to Use them Pin
sweep12312-Aug-04 4:17
sweep12312-Aug-04 4:17 
GeneralDialog Keyboard Events Pin
Joel Holdsworth10-Aug-04 22:14
Joel Holdsworth10-Aug-04 22:14 
GeneralRe: Dialog Keyboard Events Pin
Johan Rosengren11-Aug-04 6:44
Johan Rosengren11-Aug-04 6:44 
GeneralVisual C++ .net and Word 2003 automation Pin
tiziacaia10-Aug-04 21:57
tiziacaia10-Aug-04 21:57 
GeneralRe: Visual C++ .net and Word 2003 automation Pin
Steve Thresher11-Aug-04 3:04
Steve Thresher11-Aug-04 3:04 
GeneralRe: Visual C++ .net and Word 2003 automation Pin
tiziacaia11-Aug-04 4:12
tiziacaia11-Aug-04 4:12 
GeneralRe: Visual C++ .net and Word 2003 automation Pin
Steve Thresher11-Aug-04 9:32
Steve Thresher11-Aug-04 9:32 
GeneralRe: Visual C++ .net and Word 2003 automation Pin
tiziacaia11-Aug-04 18:06
tiziacaia11-Aug-04 18:06 
GeneralRe: Visual C++ .net and Word 2003 automation Pin
Steve Thresher12-Aug-04 4:36
Steve Thresher12-Aug-04 4:36 

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.