Received: from coastortho.carboarrestmiracle.com ([66.172.84.9]:45934) by stodi.digitalkingdom.org with esmtp (Exim 4.80.1) (envelope-from ) id 1XgwZR-0004nZ-6Z for lojban@lojban.org; Wed, 22 Oct 2014 07:07:30 -0700 Date: Wed, 22 Oct 2014 07:07:19 -0700 From: Doctors Insider Report Reply-to: Message-ID: <20141022072951942ZYUX84rOlrtyXf943154770407@coastortho.carboarrestmiracle.com> To: Subject: Starch and Carb Blocker Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-Spam-Score: -2.5 (--) X-Spam_score: -2.5 X-Spam_score_int: -24 X-Spam_bar: -- Did you hear about this on "The Doctors Daytime TV" show? It's a simple plan that blocks-carbs all while dropping about 6-Pounds a week. The best part is you can keep your same eating habits, so you can eat what you love. Pizza, pasta, and breads can all be eaten without guilt. http://www.carboarrestmiracle.com/refrigerates/amish/tenting.php Take a look at Oprah since she started this. She is down 17 already. Every Wednesday is "get Fit Fast Wednesday". If you have any ideas for the show please let us know. - - - - - This was shared form OWN Womens Life Broadcasting Ten Hale-Lane, Coram, NY, 1127-2902. If you are not wanting updates please change your settings http://www.carboarrestmiracle.com/acclimates/hies/simulate/ruddy/indianans/reinter.htm or you may write for setting changes. - - Oscar de la Renta dead at 82: Fashion world pours out tributes for late designer - 'The Death of Klinghoffer' turns jeers into cheers at Metropolitan Opera premiere - The Walking Dead Season 5 Episode 2 Full Video Are Now Officially Released - Before exceptions were introduced in C++: A failing new-expression produced a nullpointer. In a failing constructor one assigned a nullpointer to this. After exceptions were introduced: A failing ordinary new-expression throws an exception. In a failing constructor one throws an exception. One difference is that failure reporting for constructors now works also for creation of objects without dynamic allocation. Another difference is that code using new-expressions now can be simpler since the error handling can be moved out of each such code place, and centralized. The old nullpointer-result behavior is still available via std::nothrow (include the header). This implies checking at each place using new. Thus nullpointer results are in conflict with the DRY principle, don't repeat yourself (the redundancy offers an endless stream of opportunities to introduce errors).\ s for why you are seeing zero in this case: modern operating systems allocate memory to processes in relatively coarse-grained chunks called pages that are much larger than individual variables (at least 4KB on x86). When you have a single global variable, it will be located somewhere on a page. Assuming a is of type int[][] and ints are four bytes on your system, a[27][27] will be located about 500 bytes from the beginning of a. So as long as a is near the beginning of the page, accessing a[27][27] will be backed by actual memory and reading it won't cause a page fault / access violation. Of course, you cannot count on this. If, for example, a is preceded by nearly 4KB of other global variables then a[27][27] will not be backed by memory and your process will crash when you try to read it. Even if the process does not crash, you cannot count on getting the value 0. If you have a very simple program on a modern multi-user operating system that does nothing but allocate this variable and print that value, you probably will see 0. Operating systems set memory contents to some benign value (usually all zeros) when handing over memory to a process so that sensitive data from one process or user cannot leak to another. However, there is no general guarantee that arbitrary memory you read will be zero. You could run your program on a platform where memory isn't initialized on allocation, and you would see whatever value happened to be there from its last use. Also, if a is followed by enough other global variables that are initialized to non-zero values then accessing a[27][27] would show you whatever value happens to be there. share|improve this answer edited Oct 18 at 14:04 answered Oct 17 at 14:26 Andrew Medico 12.4k82547 3 No, you cannot assume that. Depending on compiler options it may fail to compile or it may cause a runtime error. It's also possible that other code automatically linked into your program (e.g. the C runtime library) that runs before main will happen to use that area as scratch space and put some non-zero value there. Andrew Medico Oct 17 at 14:39 1 Where are you getting 3000 from? &a[27][27] == (&a[0][0] + (27 * 4) + 27) == &a[0][0] + 135 and if sizeof(int) == 4, then 135 * sizeof(int) == 540 bytes offset from the beginning of the array. bcrist Oct 18 at 8:33 1 @AndrewMedico It depends on what level of abstraction you are working on. If you are working on the language level then you are right to say you cannot assume it. If you are working on the OS level, things change. Paul Manta 2 days ago 1 @SantiSantichaivekin No, but static values are typically stored in the .bss section. The OS will initialize this entire section with zeros. The language doesn't know about .bss, but the OS does. If you are certain your program will always run under an OS that uses a .bss section then you are safe to make some assumptions that the language alone does not allow you to. Paul Manta yesterday 2 @PaulManta Even "C program running on an OS that zeroes .bss" does not guarantee that non-faulting out-of-bounds reads will produce 0. Going outside the bounds of your own variables means you might read non-zero global variables used by your C runtime library or (on Windows) non-zero values written by AppInit DLLs. Andrew Medico yesterday show 5 more comments up vote 15 down vote Accessing an array out of bounds is undefined behavior, which means the results are unpredictable so this result of a[27][27] being 0 is not reliable at all. clang tell you this very clearly if we use -fsanitize=undefined: runtime error: index 27 out of bounds for type 'int [4][4]' Once you have undefined behavior the compiler can really do anything at all, we have even seen examples where gcc has turned a finite loop into an infinite loop based on optimizations around undefined behavior. Why is it undefined behavior, Why is out-of-bounds pointer arithmetic undefined behaviour? provides a good summary of reasons. For example, the resulting pointer may not be a valid address, the pointer could now point outside the assigned memory pages, you could be working with memory mapped hardware instead of RAM etc... Most likely the segment where static variables are being stored is much larger then the array you are allocating or the segment that you are stomping though just happens to be zeroed out and so you are just lucky in this case but again completely unreliable behavior. Most likely your page size is 4k and access of a[27][27] is within that bound which is probably why you are not seeing a segmentation fault.