🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2626

Re: volatile problem.

#2626
From: Jens M Andreasen
Date: Fri, 19 Apr 1996 14:36
48 lines
1638 bytes

On 17 Apr 1996, Joachim Huober wrote:

 > 	volatile char *foo;	/* foo points to characters that may
 > 				 * be changed by other threads
 > 				 */
 > 	char *volatile foo;	/* foo is a pointer that may be changed
 > 				 * by another thread.
 > 				 */

"May somehow change" will do. Dunno about the meaning of "thread" .

 > My problem belongs to setjmp, longjmp.
 > I want to do a setjmp, then do some fancy mallocs. if a malloc fail,
 > I want to do a longjmp and I want to free everything allocated till then.
 > 
 > char *foo = NULL;
 > char *bar = NULL;
 > jmp_buf env;
 > 
 > if (setjmp(env) == 0) {
 > 	foo = malloc(...);
 > 	if (foo == NULL) {
 > 		...
 > 		longjmp(env,1);}
 > 	bar = malloc(...);
 > 	if (bar == NULL) {
 > 		...
 > 		longjmp(env,1);}
 > } else {
 > 	if (foo != NULL)
 > 		free(foo);
 > 	if (bar != NULL)
 > 		free(bar);
 > }
 > Where do I have to write the volatile qualifier to tell the compiler not 
 > to do anything clever.

Since you are after the value of the pointer and not what it is pointing to, 
then write it like

char *volatile foo;
char *volatile bar;

// Jens M Andreasen

BTW: Are you sure that longjmp is the best way to do this ? 
Technical Details
Message-ID: <4l88d9$7bq@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4l33ku$7ns@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: Jens M Andreasen <jens-and@dsv.su.se>
Newsgroups: comp.lang.c.moderated
Subject: Re: volatile problem.
Date: 19 Apr 1996 09:36:25 -0500
Organization: Digital Solutions
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4l88d9$7bq@solutions.solon.com>
References: <4l33ku$7ns@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com