如何解决声明为“静态内联”的函数的“const”“extern”函数ptr
我只是想问问在 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 举报,一经查实,本站将立刻删除。