On 6/5/07, Thomas Hruska <[EMAIL PROTECTED]> wrote: 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). Sir Thomas, using the design principles is ok in its place (agree that they must be adhered to) but what I am saying here what if we have a piece of code which acts like a madman (won't even reject the possibility of some madman writing it) and we have been given the task of kinda rectifying it, seeing what's wrong with it. What are the places we need to look to? given that we know the following: i) single threaded application ii) uses standard C libraries iii) crashes at different locations whenever its run. My programming sense somehow tells me about the possibility of a corrupted library or even the memory. Or even segment encroachment or stack assignment errors. Wanted to know others' views about what could have happened, the symptoms being so typical, i.e. crashes at diff locations. Would love to hear from everyone who had even a near similar experience. Thanks all for your co operation, Regards, Hulk [Non-text portions of this message have been removed]
