0

根据参数中的指针大小,我有 2 个相同函数的实现:

/* Writes a $-delimited string to stdout. */   
static inline void _printmsgx(const char *msg);
#pragma aux _printmsgx = "mov ah, 9" "int 0x21" parm [ dx ] modify [ ah ];

/* Writes a $-delimited string (with far pointer) to stdout. */
static inline void _printmsgx_far(const char far *msg);
#pragma aux _printmsgx_far = "mov ah, 9" "push ds" "push es" "pop ds" "int 0x21" "pop ds" \
    parm [ es dx ] modify [ ah ];

我想自动选择调用哪个,所以我写了一个宏:

#define _printmsgx_best(msg) ((sizeof((msg)+0) == sizeof(const char*)) ? \
    _printmsgx(msg) : _printmsgx_far(msg))

但是,如果使用远指针调用它,wcc 会为未调用的分支发出警告:

foo.c(17): Warning! W112: Parameter 1: Pointer truncated
foo.c(17): Note! N2003: source conversion type is 'char __far const *'
foo.c(17): Note! N2004: target conversion type is 'char const *'

我也尝试过C11 _Generic,但 wcc 似乎不支持它:

#define _printmsgx_best(msg) _Generic((msg), \
    const char far*: _printmsgx_far(msg), const char*: _printmsgx(msg))

我收到此警告,然后出现错误:

foo.c(17): Warning! W131: No prototype found for function '_Generic'

如何在 C(不是 C++)中,在 Open Watcom V2 中使用 wcc,在小内存模型(-ms)中使其在没有警告的情况下工作?

4

0 回答 0