Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: volatile ma...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 7 Topic 26126 of 26960
Post > Topic >>

Re: volatile malloc memory?

by Antoninus Twink <nospam@[EMAIL PROTECTED] > May 9, 2008 at 08:32 PM

On  9 May 2008 at 14:01, vippstar@[EMAIL PROTECTED]
 wrote:
> On May 9, 3:06 pm, Antoninus Twink wrote:
>> #include <stdlib.h>
>> #include <string.h>
>>
>> int main(void)
>> {
>>   char *x  = malloc(128);
>>   memset(x, 0, 128);
>>   free(x);
>>   return 0;
>>
>> }
[snip]
>> Notice that even on the highest optimization level, gcc doesn't remove
>> the call to memset, even with no volatile qualifiers around, and even
>> though the memory is immediately free()d afterwards.
>
> It shouldn't; That would make your program succeed even if malloc()
> returned NULL, which with your current code is not the case.

Define succeed.

Surely if malloc() returns NULL, then passing a null pointer to memset
will invoke undefined behavior, and "success" is one possible result of
undefined behavior. I know that if you believe the regulars here, then
formatting your hard disk and generating nasal demons are the most
likely consequences of undefined behavior, but out here in the real
world, there are other possibilities...
 




 7 Posts in Topic:
volatile malloc memory?
"Dan" <voids  2008-05-09 17:36:01 
Re: volatile malloc memory?
"Dan" <voids  2008-05-09 17:41:04 
Re: volatile malloc memory?
Johannes Bauer <dfnson  2008-05-09 11:25:15 
Re: volatile malloc memory?
Antoninus Twink <nospa  2008-05-09 12:15:14 
Re: volatile malloc memory?
Antoninus Twink <nospa  2008-05-09 14:06:12 
Re: volatile malloc memory?
vippstar@[EMAIL PROTECTED  2008-05-09 07:01:55 
Re: volatile malloc memory?
Antoninus Twink <nospa  2008-05-09 20:32:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 16:40:29 CDT 2008.