|
I am trying to define a structure such that its not padded out to the nearest byte.
I did think that the directive #pragma pack(1) meant that across a 32 bit (4 byte) boundry all the bits are used.
e.g.
#pragma pack(1)
typedef struct{
unsigned long a1_t12_word_0_block_label : 12;
unsigned long a1_t12_word_0_spare_825_12 : 2;
unsigned long a1_t12_word_0_hset_ld_succ : 2;
unsigned long a1_t12_word_1_hqi_a_net : 8;
unsigned long a1_t12_word_1_hqi_b_net : 8;
unsigned long a1_t12_word_2_hqii_no : 8;
unsigned long a1_t12_word_2_hqii_non_no : 8;
unsigned long a1_t12_word_3_hqii_fmt1 : 8;
unsigned long a1_t12_word_3_hqii_fmt2 : 8;
unsigned long a1_t12_word_4_hqii_fmt3 : 8;
unsigned long a1_t12_word_4_hqii_fmt4 : 8;
unsigned long a1_t12_word_5_hqii_fmt5 : 8;
unsigned long a1_t12_word_5_hqii_fmt6 : 8;
unsigned long a1_t12_word_6_urn_no : 8;
unsigned long a1_t12_word_6_urn_non_no : 8;
unsigned long a1_t12_word_7_urn_t40_no : 8;
unsigned long a1_t12_word_7_urn_t40_non_no : 8;
unsigned long a1_t12_word_8_hqii_fmt7 : 8;
unsigned long a1_t12_word_8_hqii_fmt8 : 8;
}a1_VUHF1_T12;
The size of this structure turns out to be 20 bytes. It should be 18 bytes, how can I get it to be 18 bytes?
|
|
|
|
|
If you don't need to be ANSI C, Microsoft C lets you use unsigned short (char too). That should
get you your two-byte alignment, no?
Mark
|
|
|
|
|
Thanks Mark, that works fine.
But would like to understand why in VS 2003 unsigned long worked, but with VS 2005 I have to change to unsigned short.
Many thanks,
Andy.
|
|
|
|
|
Thanks for your help at first!
Now I'm confusing about the directions which I should choose!
I'm a senior student and have some experieces about C++ language.
Recently Micorsoft produces the Visual Studio 2005,and the C++/CLI is extremely diffrent from the standard C++.And I also learned that the MFC is numbered her days! When I want to learn the Visaul Studio 2005 development,Which direction will be my best choice.C# OR Visual C++.NET?
And could you recommend some wonderful books that will lead me comfortable to the world of Visual Studio 2005(I have no experieces in windows programming!).
|
|
|
|
|
wanlim0817 wrote: And I also learned that the MFC is numbered her days!
Gotta love the rumor mill!
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow:
I really think you are a expert on the subject of the visual C++ and the technology about the microsoft.I'm a tenderfoot about programming.I'm eager to get your help.Would you give me a detail specification that I should choose C# OR Visual C++ 2005?I will appreciate you very much for your help!
|
|
|
|
|
wanlim0817 wrote: Would you give me a detail specification that I should choose C# OR Visual C++ 2005?
No, because I've not used either of them.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Are you using the Viusal C++6.0? If you are good at her.Could you introduce some advantges and the yields of her domaining?
|
|
|
|
|
wanlim0817 wrote: Are you using the Viusal C++6.0?
Yes, exclusively.
wanlim0817 wrote: If you are good at her.
My copy is gender-neutral.
wanlim0817 wrote: Could you introduce some advantges...
Compared to what? It's 8-12 year-old technology so comparing it to a 1-2 year-old tool is hardly fair.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Friends,
I want to enumerate all the files of extension *.mp3 in a certain folder. The folder may contains subfolders and more subfolders inside subfolders. What i want is that i enumerate files upto certain "depth" of subfolders in the given folder. How can i do so ?
Imtiaz
|
|
|
|
|
Imtiaz Murtaza wrote: I want to enumerate all the files of extension *.mp3 in a certain folder.
If you are using MFC, use the CFileFind class. Otherwise, use the FindFirstFile ()/FindNextFile () pair.
Imtiaz Murtaza wrote: What i want is that i enumerate files upto certain "depth" of subfolders in the given folder. How can i do so ?
This can easily be handled via recursion.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I have just begin with VC++, Can any body help me use MS FlexGrid control? In my lab session I use Grid to add the location of Mouse (x, y) in Dialogbase. Many thanks for your help
|
|
|
|
|
It will be very difficult to help you if you don't provide any information. What are you trying to do and where are you stuck exactly ?
|
|
|
|
|
Next time, I suggest you use a more descriptive title than "help".
The title should say what you want help with - "Help using MS FlexGrid" or something like that.
|
|
|
|
|
Can any body help me use MS FlexGrid
|
|
|
|
|
Hello,
is there any funktion to convert a current time to CString?
regards
break;
|
|
|
|
|
Hi,
this is my try:
<code>
CTime t = CTime::GetCurrentTime();
CString csTime;
csTime.Format("%d:%d:%d", t.GetYear(), t.GetMonth(), t.GetDay());
</code>
thanx
break;
|
|
|
|
|
There are also formatting functions directly in the CTime class.
|
|
|
|
|
What is the standard coding practice for using the keyword virtual? I know that a base class can call a method in a derived class through virtual functions, but what if you simply want to over ride the default behaviour of a function? The virtual keyword is not always necessary but all the articles/tutorials say to use it. Also, when over riding a virtual method I sometimes see and sometimes don't see the use of virtual again in the derived class. Is there some rule about using this keyword or is it simply 'under advisment'?
|
|
|
|
|
It all depends on whether you use the base pointer, or the derived pointer
class CBase1
{
virtual void Message() { cout << "CBase!1"; }
}
class CDerived1 : public CBase1
{
virtual void Message() { cout << "CDerived1!"; }
}
class CBase2
{
void Message() { cout << "CBase2!"; }
}
class CDerived2 : public CBase2
{
void Message() { cout << "CDerived2!"; }
}
CBase1* obj1 = new CBase1();
obj1->Message();
CBase1* obj2 = new CDerived1();
obj2->Message();
CDerived1* obj3 = new CDerived1();
obj3->Message();
CBase2* obj4 = new CBase2();
obj4->Message();
CBase2* obj5 = new CDerived2();
obj5->Message();
CDerived2* obj6 = new CDerived2()
obj6->Message();
So if you have a complex class hierarchy, with lots of objects derived from a single base class, and you want to store a vector of objects, and have each perform their unique operations, you'll need to use virtual, since your vector doesn't know what type the objects are, it just thinks of them all as base class objects
|
|
|
|
|
You are talking about polymorphism, which doesn'a answer my question about when and when not virtual should be used.
|
|
|
|
|
Personally, I use virtual so I know at a glance that it may be an override.
It's your choice. It only needs to be used at the base class.
|
|
|
|
|
Looking at samples of other peoples code, I guessed this was the case. I have to admit it is handy to know quickly which methods you are overriding, but the keyword virtual here and there in the header file tends to make it a little unreadable. I like to group my function types and evenly space them, makes scanning the header a lot easier. I guess I will have to devise a method of incorporating virtual into my coding style.
|
|
|
|
|
It depends entirely on how your classes will be used. If the callers will be using polymorphism, then you need virtual on the methods that you want to be polymorphic.
virtual is only necessary in the base class. When a derived class overrides a virtual method, it's still virtual. You can write virtual in the derived class, but it's not required.
|
|
|
|
|
Hello,
I want to assign a string stored in a CString to char data type. I am unfamiliyar with char data types. They are, somehow, totally beyond my understanding!
Basically, I am getting the path of a file in strFileName. I want to extract only the file name from it. This is what I am trying to do:
if (dlg.DoModal() == IDOK)
{
strFileName.Format("%s",dlg.GetPathName());
AfxGetApp()->AddToRecentFileList(strFN);
char filePath[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
filePath = strFN;
_splitpath( filePath, drive, dir, fname, ext );
CString st; st.Format("%s%s",fname,ext);
SetWindowText(st);
pDoc->IsNew = FALSE;
}
Thanks.
Fortitudine Vincimus!
|
|
|
|