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 6 of 7 Topic 26108 of 27343
Post > Topic >>

Re: volatile malloc memory?

by vippstar@[EMAIL PROTECTED] May 9, 2008 at 07:01 AM

On May 9, 3:06 pm, some troll wrote:
> On  9 May 2008 at  7:36, Dan wrote:
>
> > What is the correct way to allocate memory that is defined as volatile
> > so that all standard compilers will not optomise out writes to the
> > memory that are never read again?
>
> What compiler are you using? How are you writing to the memory?
>
> Here's a simple program:
>
> #include <stdlib.h>
> #include <string.h>
>
> int main(void)
> {
>   char *x  = malloc(128);
>   memset(x, 0, 128);
>   free(x);
>   return 0;
>
> }
>
> Here's the start of the code produced by gcc with -O3 optimization
> level:
<possible gcc output>
> 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.
 




 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 Sat Sep 6 21:14:58 CDT 2008.