Skip to content

Commit 69308a3

Browse files
authored
Add void to empty parameter list to fix -Werror=strict-prototypes error (#26016)
Compiling C application dependent on onnxruntime with flag -Werror=strict-prototypes results in an error because the function declarations without parameters are considered to have an implicit int parameter list, which is not allowed in strict prototype mode. To fix this, we need to explicitly specify void in the parameter list of functions that do not take any arguments. ### Description <!-- Describe your changes. --> ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> When compiling a C program that depends on ONNX Runtime with the `-Werror=strict-prototypes` flag enabled, the build fails due to function declarations in `onnxruntime_c_api.h` that are not strict prototypes. For example, in the **onnxruntime-inference-examples** project, the following errors are reported: ``` ~/install/onnxruntime/include/onnxruntime_c_api.h:4929:3: error: function declaration isn't a prototype [-Werror=strict-prototypes] const OrtModelEditorApi*(ORT_API_CALL* GetModelEditorApi)(); ^~~~~ ~/install/onnxruntime/include/onnxruntime_c_api.h:4987:3: error: function declaration isn't a prototype [-Werror=strict-prototypes] const OrtCompileApi*(ORT_API_CALL* GetCompileApi)(); ^~~~~ ~/install/onnxruntime/include/onnxruntime_c_api.h:5253:3: error: function declaration isn't a prototype [-Werror=strict-prototypes] const OrtEpApi*(ORT_API_CALL* GetEpApi)(); ^~~~~ ``` This occurs because function declarations with empty parentheses are not considered proper prototypes in C, and strict prototype checking treats this as an error. Our project uses ONNX Runtime and enforces -Werror=strict-prototypes in our build system. It would be very helpful if these declarations in ONNX Runtime could be updated to use (void) for functions that take no arguments, so that strict prototype builds succeed without errors. Signed-off-by: Lifang Zhang <[email protected]>
1 parent 06a3ccf commit 69308a3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/onnxruntime/core/session/onnxruntime_c_api.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5108,7 +5108,7 @@ struct OrtApi {
51085108
*
51095109
* \since Version 1.22.
51105110
*/
5111-
const OrtModelEditorApi*(ORT_API_CALL* GetModelEditorApi)();
5111+
const OrtModelEditorApi*(ORT_API_CALL* GetModelEditorApi)(void);
51125112

51135113
/** \brief Create an OrtValue for a Tensor that uses pre-existing memory.
51145114
*
@@ -5166,7 +5166,7 @@ struct OrtApi {
51665166
*
51675167
* \since Version 1.22.
51685168
*/
5169-
const OrtCompileApi*(ORT_API_CALL* GetCompileApi)();
5169+
const OrtCompileApi*(ORT_API_CALL* GetCompileApi)(void);
51705170

51715171
//
51725172
// OrtKeyValuePairs
@@ -5434,7 +5434,7 @@ struct OrtApi {
54345434
*
54355435
* \since Version 1.22.
54365436
*/
5437-
const OrtEpApi*(ORT_API_CALL* GetEpApi)();
5437+
const OrtEpApi*(ORT_API_CALL* GetEpApi)(void);
54385438

54395439
/** \brief Compute total size in bytes of the tensor data contained in an OrtValue.
54405440
*

0 commit comments

Comments
 (0)