我正在维护一个必须运行 Alpha OpenVMS (7.3-2) 和 Itanium OpenVMS (8.4) 的应用程序。它是用 C++ 编写的,编译器版本在 Alpha 上是 6.5-046,在 IA64 上是 7.4-004。
我遇到的问题是 LIB$SIGNAL()。一旦它发出致命消息,程序就会中止。
首先是重现此代码的代码(作为生成和构建代码的 DCL 脚本):
$ create mtst.msg
.TITLE Message file for MTST
.IDENT 'VERSION 1.1'
.FACILITY MTST,1 /PREFIX=MTST_
.SEVERITY INFORMATIONAL
HELLO <Hello World> /fao_count=0
.SEVERITY SUCCESS
SUCCESS <Opdracht succesvol uitgevoerd> /fao_count=0
.SEVERITY WARNING
WHOOPS <Dit is een waarschuwing: !AZ> /fao_count=1
.SEVERITY ERROR
WHAAA <Oeioeioei dat was op het randje> /fao_count=0
.SEVERITY FATAL
AARGH <Nu is het helemaal mis> /fao_count=0
.END
$!
$ create msgtest.h
#define __NEW_STARLET 1
#include<lib$routines.h>
#include<stsdef.h>
#pragma extern_model globalvalue
extern unsigned long MTST_HELLO;
extern unsigned long MTST_SUCCESS;
extern unsigned long MTST_WHOOPS;
extern unsigned long MTST_WHAAA;
extern unsigned long MTST_AARGH;
#pragma extern_model relaxed_refdef
$!
$ create msgctest.c
#include<msgtest.h>
#include<stdio>
#include<stdlib.h>
int main(void) {
char* msgArgument = "Boe!";
printf ("Test: info message...\n");
LIB$SIGNAL(MTST_HELLO);
printf("\n");
printf ("Test: success message...\n");
LIB$SIGNAL(MTST_SUCCESS);
printf("\n");
printf ("Test: warning message...\n");
LIB$SIGNAL(MTST_WHOOPS, 1, msgArgument);
printf("\n");
printf ("Test: error message...\n");
LIB$SIGNAL(MTST_WHAAA);
printf("\n");
printf ("Test: fatal message...\n");
LIB$SIGNAL(MTST_AARGH);
printf("\n");
printf ("Einde test!\n");
}
$!
$ create msgtest.cpp
#include<msgtest.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
#include <chfdef.h>
int main(void) {
char* msgArgument = "Boe!";
cout << "Using IOStream:" << endl << "Test: info message..." << endl;
LIB$SIGNAL(MTST_HELLO);
cout << endl << "Test: success message..." << endl;
LIB$SIGNAL(MTST_SUCCESS);
cout << endl << "Test: warning message..." << endl;
LIB$SIGNAL(MTST_WHOOPS, 1, msgArgument);
cout << endl << "Test: error message..." << endl;
LIB$SIGNAL(MTST_WHAAA);
cout << endl << "Test: fatal message..." << endl;
LIB$SIGNAL(MTST_AARGH);
// Next line is, of course, never displayed...
cout << endl << "Einde test!" << endl;
}
$!
$! Compile the message file
$ message mtst
$!
$! As a reference, build an executable using the C-source. Will always work both on Alpha and Itanium
$ cc/lis=[] /include=[] msgctest.c /warn=(disa=dollarid)/notrace
$ link msgctest,mtst /map=[]/cross/notrace
$!
$! Now build the C++ based exe.
$ cxx/lis=[]/reposi=[] /include=[] msgtest.cpp /warn=(disa=dollarid)/notrace/standard=strict_ansi
$! Using this compile statement it works on Itanium:
$! cxx/lis=[]/reposi=[] /include=[] msgtest.cpp /warn=(disa=dollarid)/notrace
$! Using this compile statement it fails again:
$! cxx/lis=[]/reposi=[] /include=[] msgtest.cpp /warn=(disa=dollarid)/notrace/define=(__USE_STD_IOSTREAM)
$ cxxlink msgtest,mtst /map=[]/cross/notrace
$!
C 源代码始终有效,并且在 Alpha 上两个脚本都有效。
在没有 /STANDARD 的情况下进行编译时,它在 Itanium 上运行良好,但在原始程序中我在使用 iostream 时遇到了问题:我需要 ANSI,但使用 /DEFINE=(__USE_STD_IOSTREAM) 进行编译时又回到了原来的问题。
$r msgtest
Test: info message...
%MTST-I-HELLO, Hello World
Test: success message...
%MTST-S-SUCCESS, Opdracht succesvol uitgevoerd
Test: inwarningfo message...
%MTST-W-WHOOPS, Dit is een waarschuwing: Boe!
Test: error message...
%MTST-E-WHAAA, Oeioeioei dat was op het randje
Test: fatal message...
%CXXL-F-TERMINATING, terminate() or unexpected() called
$
我期望的是:
$ r msgctest
Test: info message...
%MTST-I-HELLO, Hello World
Test: success message...
%MTST-S-SUCCESS, Opdracht succesvol uitgevoerd
Test: warning message...
%MTST-W-WHOOPS, Dit is een waarschuwing: Boe!
Test: error message...
%MTST-E-WHAAA, Oeioeioei dat was op het randje
Test: fatal message...
%MTST-F-AARGH, Nu is het helemaal mis
$
所以... %CPP-?-WTF,请帮助:-/
在此先感谢,奥斯卡
注意:在我昨天发布的原始帖子中,有一个不同的脚本,其中包含更多的测试代码,例如 try/catch。当然,这改变了测试结果,正如他/她的评论中所说的 user2116290。我将 DCL 脚本更改为原始测试,以重现我在原始应用程序中看到的内容。