问题描述
我只是想问问在 C 中使用“extern const”函数指针来暴露“静态内联”函数是否是一种好的风格。
示例:
lib.c:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Request</title>
<Meta charset="utf-8">
<Meta name="viewport" content="width=device-width,initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<form target="_blank">
<!-- Radio buttons for request type. Subsequent input fields will appear depending upon the request type -->
<input type="radio" required name="type" id="ADD" class="reqType">
<label class="form-check-label" for="ADD">Add new report</label>
<input type="radio" name="type" id="DELETE" class="reqType">
<label class="form-check-label" for="DELETE">Delete report</label>
<!-- 'Add report' fields -->
<div class="optionalInfo newRepData">
<label for="reportId">New Report ID :</label>
<input type="text" name="reportId" id="reportId">
<label for="reportName">New Report Name :</label>
<input type="text" name="reportName" id="reportName">
</div>
<br><br><input type="submit" value="Submit Request">
</form>
</body>
</html>
lib.h
static inline int add(int x,int y) {return x+y;}
const int(*add_func)(int,int) = add;
main.c
extern const int(*add_func)(int x,int y);
我这样做的原因是:
但我觉得这很混乱,如果 LTO 工作不正常,实际上可能会给函数调用增加一些开销。
那么问题是,我应该避免这种模式吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)