suchismit mahapatra wrote:
> Hi people,
>                   Had a few queries. Wanted to share with the group.
> 
> What is the whole thing associated with the "pragma pack" jargon? How does
> it decide the memory to be allocated to a collection of objects. How does it
> work internally?

#pragma pack() declares how many bytes structure/class elements take. 
By default, compiler authors usually system byte-align elements.  So on 
a 32-bit platform, elements are 32-bit aligned.  Kind of 
counter-intuitive but it allows assembler instructions to be optimized.

#pragma pack() forces the compiler to generate non-optimal code for the 
platform.  Usually when one uses the directive, it is to byte-align 
structures.  In general, you don't want to use this directive unless you 
know exactly what you are doing and absolutely need it.


> What are the possible causes of a piece of C code crashing and that too in
> different points of the code when it is executed, given that it uses just
> the standard C libraries and is single threaded.
> Where should one look for the flaws?

Write code such that it can't crash in the first place.  Read Safe C++ 
Design Principles (free e-book for c-prog members).


> How would it be different if the application was multi threaded? used other
> user defined libraries?
> Where would one look then?

You might want to get yourself a good debugger/IDE.  Visual Studio .NET 
currently has the best C/C++ debugger on the planet.  The next best 
option would probably be KDevelop (Linux) or Dev-C++ (Windows).

Debuggers allow you to step through code and most modern OSes have 
built-in support for exception handling and provide at least a call 
stack which the debugger can walk.  That is, you should be able to run 
the code to the point of the crash and then start setting breakpoints 
around where it starts making sense.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* VerifyMyPC 2.5
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.

http://www.CubicleSoft.com/VerifyMyPC/

Reply via email to