Is it possible to do a #define NORETURN(x)
macro that works with the Open Watcom C compiler (not C++)?
Based on the fine manual I have this file test.c
:
#include <stdlib.h>
#ifdef __GNUC__
#define STATIC_NORETURN(sig) static void sig __attribute__((__noreturn__))
#define EXTERN_NORETURN(sig) extern void sig __attribute__((__noreturn__))
#endif
#ifdef __WATCOMC__
#pragma aux noreturn aborts;
#define STATIC_NORETURN(sig) static void __pragma("noreturn") sig
#define EXTERN_NORETURN(sig) extern void __pragma("noreturn") sig
#endif
STATIC_NORETURN(my_static_example(void));
EXTERN_NORETURN(my_extern_example(void));
static void my_static_example(void) {
exit(0);
}
void my_extern_example(void) {
my_static_example();
}
It compiles without any errors or warnings using GCC:
$ gcc -Wall -Wextra -pedantic -std=gnu99 -c test.c
But not using Open Watcom 1.9:
$ wine wcc386 -q -wx test.c
test.c(14): Error! E1009: Expecting ')' but found 'noreturn'
test.c(14): Error! E1026: Invalid declarator
test.c(14): Error! E1009: Expecting ',' but found 'noreturn'
test.c(14): Error! E1026: Invalid declarator
test.c(14): Error! E1009: Expecting ',' but found ')'
test.c(14): Error! E1024: Declared symbol 'my_static_example' is not in parameter list
test.c(15): Error! E1023: Storage class of parameter must be register or unspecified
test.c(15): Error! E1009: Expecting ')' but found 'noreturn'
test.c(15): Error! E1024: Declared symbol '__pragma' is not in parameter list
test.c(15): Error! E1009: Expecting ',' but found 'noreturn'
test.c(15): Error! E1026: Invalid declarator
test.c(15): Error! E1009: Expecting ',' but found ')'
test.c(15): Error! E1024: Declared symbol 'my_extern_example' is not in parameter list
test.c(17): Error! E1023: Storage class of parameter must be register or unspecified
test.c(17): Error! E1024: Declared symbol 'my_static_example' is not in parameter list
test.c(17): Error! E1076: Missing semicolon at end of declaration
test.c(22): Warning! W131: No prototype found for function 'my_static_example'
test.c(14): Warning! W202: Symbol '__pragma' has been defined, but not referenced
Upon closer reading, I think the manual says that __pragma
works only in C++ code for some reason. But I'm not sure I understood that correctly. Is there any equivalent for C that doesn't require the use of #pragma
at the site of each function definition? I'm trying to avoid ifdefs so it'd be nice to define a portable NORETURN macro in one central place.
Reading https://open-watcom.github.io/open-watcom-v2-wikidocs/cguide.html it's:
Be compatible with stdnoreturn.h, don't come up with your own style. Do:
Compiles fine on
wcc386 -q -wx test.c
withVersion 2.0
.