gpt4 book ai didi

c - AIX 上的函数指针编译错误

转载 作者:行者123 更新时间:2023-11-30 19:12:49 28 4
gpt4 key购买 nike

我正在尝试在 IBM AIX 中编译一些 C 代码,但它似乎在函数指针方面存在一些严重问题。

以下是一些无法编译的代码:

typedef int (*strategy_fn)(const unsigned short va_niveau_trace, const unsigned int va_indentation_trace, const char* va_finalstring);

typedef struct strategy_tab_item_
{
TraceStrategy strategy;
strategy_fn fn;
}strategy_tab_item, *strategy_tab_item_ptr;

const strategy_tab_item tab_strategy[] =
{
{TRACE_NO_BUFFERING, trace_process_no_buffering},
{TRACE_LOOSE_CURRENT, trace_process_loose_current},
{TRACE_LOOSE_OLDEST, trace_process_loose_oldest},
{TRACE_AUTO_SYNC, trace_process_auto_sync}
};

AIX 不支持上面代码中编写的 typedef(同时定义 2 个),我将它们分开:

typedef struct strategy_tab_item_
{
TraceStrategy strategy;
strategy_fn fn;
} strategy_tab_item;

typedef struct strategy_tab_item_ *strategy_tab_item_ptr;

现在 strategy_fn 无法识别(语法错误)。

最佳答案

您引用的代码不完整。试试这个:

typedef int strategy_fn (const unsigned short va_niveau_trace, 
const unsigned int va_indentation_trace,
const char *va_finalstring);

strategy_fn trace_process_no_buffering,
trace_process_loose_current,
trace_process_loose_oldest,
trace_process_auto_sync;

typedef enum TraceStrategy {
TRACE_NO_BUFFERING,
TRACE_LOOSE_CURRENT,
TRACE_LOOSE_OLDEST,
TRACE_AUTO_SYNC
} TraceStrategy;

typedef struct strategy_tab_item_
{
TraceStrategy strategy;
strategy_fn *fn;
} strategy_tab_item, *strategy_tab_item_ptr;

const strategy_tab_item tab_strategy[] =
{
{TRACE_NO_BUFFERING, trace_process_no_buffering},
{TRACE_LOOSE_CURRENT, trace_process_loose_current},
{TRACE_LOOSE_OLDEST, trace_process_loose_oldest},
{TRACE_AUTO_SYNC, trace_process_auto_sync}
};

关于c - AIX 上的函数指针编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36406175/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com