Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BCB內structure的size...

0 views
Skip to first unread message

長不大的老孩子...

unread,
Feb 2, 1999, 3:00:00 AM2/2/99
to

問題是這樣的,
在BCB 3.0 C/S中,IDE內預設 /Project/Options/Advanced Compiler選項內
之Data Alignment原設定為Double Word, 若程式裡有一個structure及一程式
片斷為
__fastcall TForm1::TForm1(TComponent* Owner) : Form(Owner)
{
struct {
int a;
char b;
int c;
} abc;

}
在step trace中利用Watches windows來觀看執行中的結果, structure abc的
size為12...

依各變數的size:
sizeof(int) = 4;
sizeof(char) = 1;
整個structure abc 的size不是應該為4 + 1 + 4 = 9嗎?

若將/Project/Options/Advanced Compiler選項內之Data Alignment設定
為Byte,在執行後,會出現下列Access Violation的message box:
-------------------------------------------------------------------
Project Project.exe raised exception class EAccess Violation with
message 'Access violation at address XXXXXXXX in module 'VCL35.BPL'.
Read of address XXXXXXXX'.
Process stopped. Use Step or Run to continue.
-------------------------------------------------------------------

請問有沒有人遇到這種情況啊? (Access Violation ? 程式裡並沒有作變數
的存取啊...)

若有, 請問這個情況的解決方式為何?

謝謝﹗﹗

--
想想看.........

這時候,全世界的人正在做什麼.....
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>

思思 Michael Liang

unread,
Feb 2, 1999, 3:00:00 AM2/2/99
to
==> 在 prism@cis_nctu (長不大的老孩子...) 的文章中提到:

> 問題是這樣的,
> 在BCB 3.0 C/S中,IDE內預設 /Project/Options/Advanced Compiler選項內
> 之Data Alignment原設定為Double Word, 若程式裡有一個structure及一程式
> 片斷為
> __fastcall TForm1::TForm1(TComponent* Owner) : Form(Owner)
> {
> struct {
> int a;
> char b;
> int c;
> } abc;
> }
> 在step trace中利用Watches windows來觀看執行中的結果, structure abc的
> size為12...
> 依各變數的size:
> sizeof(int) = 4;
> sizeof(char) = 1;
> 整個structure abc 的size不是應該為4 + 1 + 4 = 9嗎?
===============
根據inside the c++ object model
裡面說的...
你還必須加上..
加上任何由於alignment的需求而填補上去的空間..所以加起來就是12
你可以看這本書的中譯本第83頁至88頁..有說明喲..

--
ID: szu
Name: 思思 Michael Liang
Email: lmi...@ms7.url.com.tw
一位來自南台灣喜歡程式設計正努力設計程式的電腦人

長不大的老孩子...

unread,
Feb 6, 1999, 3:00:00 AM2/6/99
to
==> 在 szu@cis_nctu (思思 Michael Liang) 的文章中提到:

> > 在step trace中利用Watches windows來觀看執行中的結果, structure abc的
> > size為12...
> > 依各變數的size:
> > sizeof(int) = 4;
> > sizeof(char) = 1;
> > 整個structure abc 的size不是應該為4 + 1 + 4 = 9嗎?
> ===============
> 根據inside the c++ object model
> 裡面說的...
> 你還必須加上..
> 加上任何由於alignment的需求而填補上去的空間..所以加起來就是12
> 你可以看這本書的中譯本第83頁至88頁..有說明喲..

再請問一下,若要從一個檔案中去讀有這種structure 的資料, 是不是就要做這些
"填補"的工作??!?! 那不會變得很麻煩嗎? 沒法真接從檔案裡從出整個structure
的image 嗎? 有沒有其它的解決辦法啊??!?


--
想想看.........

這時候,全世界的人正在做什麼.....

mj...@ms1.hinet.net

unread,
Feb 22, 1999, 3:00:00 AM2/22/99
to

>==> 在 szu@cis_nctu (思思 Michael Liang) 的文章中提到:
>> > 在step trace中利用Watches windows來觀看執行中的結果, structure abc的
>> > size為12...
>> > 依各變數的size:
>> > sizeof(int) = 4;
>> > sizeof(char) = 1;
>> > 整個structure abc 的size不是應該為4 + 1 + 4 = 9嗎?
>> ===============
>> 根據inside the c++ object model
>> 裡面說的...
>> 你還必須加上..
>> 加上任何由於alignment的需求而填補上去的空間..所以加起來就是12
>> 你可以看這本書的中譯本第83頁至88頁..有說明喲..
> 再請問一下,若要從一個檔案中去讀有這種structure 的資料, 是不是就要做這些
> "填補"的工作??!?! 那不會變得很麻煩嗎? 沒法真接從檔案裡從出整個structure
> 的image 嗎? 有沒有其它的解決辦法啊??!?

試著用以下方式解決吧 !

#pragma option push
#pragma option -a1
定義資料結構
#pragma option pop


Jd.Mai


0 new messages