Thread View: comp.lang.c.moderated
2 messages
2 total messages
Started by Joachim Huober
Wed, 17 Apr 1996 15:44
volatile problem.
Author: Joachim Huober
Date: Wed, 17 Apr 1996 15:44
Date: Wed, 17 Apr 1996 15:44
51 lines
1834 bytes
1834 bytes
Hi all,
Is volatile the oposite of const, and do the tricky things about const
also belong to volatile.
Exp:
const char *foo; /* foo points only to characters that
* will not be changed through foo
*/
char *const foo; /* foo is an unchanging pointer to a
* possibly changing char.
*/
Does this correspond to:
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.
*/
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.
Joachim
--
---------------------------------------------------------------------
Joachim Huober Phone: +49 731 502-6241
UDINE-Project, URZ, University of Ulm, 89081 Ulm , Germany
E-mail: joachim.huober@rz.uni-ulm.de
---------------------------------------------------------------------
Re: volatile problem.
Author: Jens M Andreasen
Date: Fri, 19 Apr 1996 14:36
Date: Fri, 19 Apr 1996 14:36
48 lines
1638 bytes
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 ?
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads