|
Can we find out the size of a structure without using sizeof function?
I have tried to write a macro passing the name of the structure as a parameter, but it did not work as expected!! Is there anyother way to do this?
Please provide your valuable suggestions and code(if possible).....
R@j@$eg@r
|
|
|
|
|
Yes.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Homework-time, eh?
Hint: You can get adresses of struct members...
Failure is not an option - it's built right in.
|
|
|
|
|
Even sizeof usage is hazardous on Win32 structures.
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.
|
|
|
|
|
Why?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Since we are working on generating metadata about a structure by supplying the name of the structure, and getting its size during run time!!
R@j@$eg@r
|
|
|
|
|
This makes no sense. How does it answer the question, "Why is sizeof usage hazardous on Win32 structures?"
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hint: BITMAPINFO
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.
|
|
|
|
|
Is its size undetectable?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Of course it is detectable. But its actual size cannot be detected with a naive use of sizeof , i.e. it's tricky!
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.
|
|
|
|
|
I agree. sizeof will return different size for the same structure if executed in different platforms i.e linux vs windows and thus different compilers. This is due to padding and alignment of members for optimization purposes in the memory. There are macros or compiler options that can be used to eliminate padding i.e to use 1 byte padding always. If i remember correctly this will be the "pack(1)" macro and in Visual C++ the compiler option /Z1 (I think) can be used to force 1 byte padding. This will give more consistent results with sizeof... .
|
|
|
|
|
Emmanouil wrote: I agree. sizeof will return different size for the same structure if executed in different platforms i.e linux vs windows and thus different compilers.
I'm not exactly sure what you are agreeing to, but, for example, sizeof(int) will also return different results on different platforms. That's not a fault with the sizeof operator, however.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
There is some crap being posted here.
The only time this is an issue is when you receive a pointer to a structure. If you receive a structure, the Compiler will know the size from the declaration. The Windows Standard way of dealing with pointers to structures of variable size is by using a member c_Bytes as the first member of a structure. This member must be guaranteed to always be initialised to the size of the structure. However, this is only the top of the iceberg, the problem is far larger, particularly if you deal with data structures generated by different compilers. For starters there is the Packing Method. The Structure {char Name[5],PhoneNumber[7]}; would by default be compiled into an object of 16 (NOT 12) bytes. An extra 3 bytes would be placed after Name to make PhoneNumber start at a DWORD boundary, and an extra byte would then be added to the entire structure, so that an array of it would have each element on a DWORD boundary.
You can control this behaviour with a #pragma pack in the header file that declares the structure. (packing for a structure is set at Declaration level, NOT at Useage level). #pragma pack(1) would indeed create a 12 byte structure.
Another issue is when you use structures generated by different compilers are dependent on issues of the kind of 'Howmany bytes does an int occupy'. You can circumvent a lot of this by using WORD and DWORD types, which most( but not All) compiler writers agree occupy 2 resp 4 bytes. Do not forget, an int under WIN16 was 2 Bytes, under WIN32 it is 4. So, the same Structure Declaration will lead to entrely different Sizes and Offsets under WIN16 compared to WIN32.
Returning to your original question: Is there a (generic)way of determining the Size of a Structure without using the sizeof operator, the answer is No, Definitely Not. sizeof is not a function, it is a reserved name which the compiler at compile time resolves to the size of the object by reference to the symbol table. If the size is not known at compile time, the compiler provides NO alternative mechanism, you must create your own runtime mechanism to transmit the size of the object a pointer points to inside the object.
LateNightsInNewry
|
|
|
|
|
>>There is some crap being posted here.
And you're validating the posted crap with your long winded diatribe
Yours Truly, The One and Only!
|
|
|
|
|
I wrote a program to convert mpeg file to avi in directshow, now the conversion is OK, but I can't find out a method to seek the source media, I want to seek to a given point in source media before the conversion begin. In other words, I want to convert a segment of mpeg file to avi file. The structure of my program is following: 1. Read source mpeg file by using pGraph->AddSourceFilter(...); 2. Init IMediaSeeking, IMediaControl, etc by query pGraph; 3. Setup output avi file and init pMux by using pBuilder->SetOutputFileName(...); 4. Create Mpeg splitter and Mpeg Decoder then add them to pGraph; 5. Connect all filters by using pBuilder->RenderStream(....); 6. Start conversion by using pMediaControl->run(). now the conversion of whole mpeg file is OK, but I can't seek the source media, the pMediaSeeking->SetPositions(...) and GetDuration() function always return fail. I also tried to seek media by pMux but failed. someone can give me instruction to resolve it? thanks in advance.
|
|
|
|
|
Did you get my response to your email (maybe your email filter ate it or i didn't help you
any )?
It was something like:
I’m not sure if you can seek in that type of graph.
If you follow the guidelines at Seeking the Filter Graph[^] you’ll find out if it works or not
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
Thank you very much. I checked my mailbox and not found your mail.(maybe the antivirus software ate it ), however after I follow your instruction to read the "Seeking the Filter Graph" in MSDN, I still can't find out the answer, It only tell me how to seek the media for rendering the media on screen, I also use pMediaSeeking->GetCapabilities(...) to check if it supports seeking, it return S_OK.
|
|
|
|
|
Can any one solve this issue of mine
I am getting this error
fatal error C1083: Cannot open include file: 'dshow.h': No such file or directory
but I have installed directx 9.0
S.Yamini
|
|
|
|
|
check under
tools -> Options->projects and solutions, VC++ Directories
that the include directory in present.
if it is... copy the dir path, go to explorer check that the file you need is in that directory.
hope that fix's it
|
|
|
|
|
I went to tools->options but i dont find projects and solutions tab but i find directories where I have entered the include files.But still the error occurs
S.Yamini
|
|
|
|
|
oh my fault, assumed you were using VS 2005
...i cant remember VS6 errm
you could try a direct include
eg
#include "C:\program files\dx\inc\file.h"
something like that might help
hope someone else can give a better solution
i'll check VS6 when i get home, no longer supported at work
sorry about that.
|
|
|
|
|
go to menu Tools->options, click "Directories" tab in option dialog, input "c:\dxsdk\include" (your directx installation directory), then move it to top.
|
|
|
|
|
open the menu options, go to the directories tab and add the directx include paths on top of all include paths in the IDE directories.
k_dehairy
|
|
|
|
|
yaminisridaran wrote: but I have installed directx 9.0
So have you checked to see if dshow.h actually exists on your machine?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Sorry for the late reply. I have install the directX SDK june2007 but still I am taking same 46 errors. I have included the directories.Please help me to solve this issue
S.YAmini
|
|
|
|