[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
Title: | DEC C Problem Reporting Forum |
Notice: | Report DEC C++ problems in TURRIS::C_PLUS_PLUS |
Moderator: | CXXC::REPETE TCHEON |
|
Created: | Fri Nov 13 1992 |
Last Modified: | Fri Jun 06 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 1299 |
Total number of notes: | 6249 |
1264.0. "setjmp/longjmp problem" by UTRTSC::WDEBAKKER (Feed your head) Mon Feb 17 1997 07:38
Hello,
A customer reported a problem with setjmp/longjmp, which is
reproducable with DEC C V5.5-002 on OpenVMS Alpha V6.2.
It works fine, however, with DEC C V5.5-002 and OpenVMS VAX V6.2
Below is a short reproducer.
Any ideas how this could be solved?
Thanks in advance,
Willem de Bakker
/*
* Copyright, Fuji Photo Film B.V, Tilburg
*
* DESCRIPTION
* Description of incorrect behaviour of the DECC compiler when
* volatile variables should not be optimized.
*
* According to the DECC run time library reference manual:
* "The setjmp function preserves the hardware general pur-
* pose registers, and the longjmp function restores them. After
* a longjmp, all variables have their values as of the time of
* the longjmp except for local automatic variables not marked
* volatile. These variables have indeterminate values"
*
* In short: In the example below MyCharp must preserve its value which it
* does not.
* Compiled, linked and run as:
* $ CC/DEBUG/NOOPTIMIZE <file>
* $ LINK <file>
* $ RUN <file>
* MyCharp: 0 (null)
*
* The behaviour was introduced when upgrading from AXP DECC
* v4.1 to v5.2 and continues to exist in DECC v5.5.
* In the v4.1 era, the compiler did not use any registers at all
* if /DEBUG/NOOPTIMIZE were passed as options. From v5.2 on it does, even
* when not allowed.
*
* Kind regards,
*
* Arie van Wijngaarden
* e-mail: [email protected]
* HISTORY
* 17-FEB-1997, AvW
* Created.
*/
#include <stdio.h>
#include <setjmp.h>
int main()
{
volatile const char *MyCharp = 0;
jmp_buf JumpContext;
if (setjmp(JumpContext) == 0)
{
MyCharp = "Hallo boppers";
longjmp(JumpContext, 1);
}
printf("MyCharp: %x %s\n", MyCharp, (MyCharp) ? MyCharp : "(null)");
}
T.R | Title | User | Personal Name | Date | Lines |
---|
1264.1 | Confusing placement of volatile | WIBBIN::NOYCE | Pulling weeds, pickin' stones | Mon Feb 17 1997 08:49 | 6 |
| > volatile const char *MyCharp = 0;
This declares that MyCharp is a pointer to a volatile const char.
You probably wanted MyCharp to be volatile itself:
const char * volatile MyCharp = 0;
|
1264.2 | | UTRTSC::WDEBAKKER | Feed your head | Mon Feb 17 1997 08:58 | 18 |
|
Thanks,
but is the code in .0 incorrect?
As it worked fine on the VAX platform, and it used to
work with DEC C V4.2, the customer's likely to
point to the upgrade to DEC C V5
He wrote to me:
After upgrading from DECC v4.2 to 5.x a problem arised when using
setjmp/longjmp combinations in C sources. According to the documentation,
a longjmp may influence the values of the local automatic variables
which are not marked volatile. However, it also influences the values
for automatic pointer variables declared volatile (see example below).
Note that the behaviour is correct for automatic int variables declared
volatile as well as variables declared static or extern.
Thanks,
Willem
|
1264.3 | Yes, the code in .0 is incorrect. | WIBBIN::NOYCE | Pulling weeds, pickin' stones | Mon Feb 17 1997 09:25 | 4 |
| The customer *doesn't have* a pointer variable declared volatile.
Since MyCharp in .0 is not volatile, its value after longjmp is
indeterminate.
|
1264.4 | | DECCXL::OUELLETTE | | Wed Feb 19 1997 17:00 | 7 |
| Just to add a nail to the coffin...
With the old compilers, your customer's indeterminate value
hid your coustomer's bug. Their code needs to be fixed to work
by forcing a determinate value.
R.
|
1264.5 | Dig it | UTRTSC::WDEBAKKER | Feed your head | Thu Feb 20 1997 03:14 | 6 |
| OK, Thanks for your replies.
I'll see to it that this coffin gets buried
Cheers,
Willem
|