【发布时间】:2021-02-15 11:01:40
【问题描述】:
我正在使用 C++ 库,但由于某种原因,我必须转换为以下结构的 C。
我从 github 找到了一个 C++ 库,它有这样的结构:
struct BRIDGE_TREE
{
...
void SetBridgeIdentifier (unsigned short settablePriorityComponent, unsigned short treeIndex, const unsigned char address[6])
{
BridgeIdentifier.SetPriorityAndMstid (settablePriorityComponent, treeIndex);
BridgeIdentifier.SetAddress (address);
UpdateBridgePriorityFromBridgeIdentifier();
}
..}
这个结构和函数在下面的函数中调用:
STP_BRIDGE* STP_CreateBridge (unsigned int portCount,
unsigned int mstiCount,
unsigned int maxVlanNumber,
const STP_CALLBACKS* callbacks,
const unsigned char bridgeAddress[6],
unsigned int debugLogBufferSize)
{
STP_BRIDGE* bridge = (STP_BRIDGE*) callbacks->allocAndZeroMemory (sizeof (STP_BRIDGE));
assert (bridge != NULL);
...
bridge->trees [CIST_INDEX]->SetBridgeIdentifier (0x8000, CIST_INDEX, bridgeAddress);
..
}
我怎样才能像这样在 C 中使用SetBridgeIdentifier 函数。我正在寻找解决方案很长时间。我是 C++ 新手。
【问题讨论】:
-
您的意思是:您想用 C 重新编写库还是:该库可以用 C++ 编写,但您希望能够从 C 中使用它?
-
不考虑库的关系,我不会转换库,我只是问如何将相应的struct函数转换为C。专注于没有图书馆的主要问题。
-
我的问题不在于这是关于库还是只是一个功能。关键是您是否只想能够从 C 中调用函数,或者想用 C 重写函数。
-
我想用C重写函数。我已经可以用C运行C++代码了。我的目标是学习如何用C编写函数
-
bridge->trees [CIST_INDEX]->SetBridgeIdentifier (0x8000, CIST_INDEX, bridgeAddress)不调用void SetBridgeIdentifier (const BRIDGE_ID& newBridgeIdentifier)。那是两个不同的功能。你到底想转换什么?