Skip to content

Add void to empty parameter list to fix -Werror=strict-prototypes error - #26016

Merged
edgchen1 merged 1 commit into
microsoft:mainfrom
lifang-zhang:fix-strict-prototype-error
Sep 17, 2025
Merged

Add void to empty parameter list to fix -Werror=strict-prototypes error#26016
edgchen1 merged 1 commit into
microsoft:mainfrom
lifang-zhang:fix-strict-prototype-error

Conversation

@lifang-zhang

@lifang-zhang lifang-zhang commented Sep 11, 2025

Copy link
Copy Markdown
Contributor

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

Motivation and Context

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.

Comment thread include/onnxruntime/core/session/onnxruntime_c_api.h Outdated
Compiling C application dependent on onnxruntime with flag
-Werror=strict-prototypes flag 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.

Signed-off-by: Lifang Zhang <lifang.zhang@nokia.com>
@lifang-zhang
lifang-zhang force-pushed the fix-strict-prototype-error branch from e337c88 to b55f954 Compare September 15, 2025 06:51
@edgchen1

Copy link
Copy Markdown
Contributor

/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 4 pipeline(s).

@edgchen1
edgchen1 merged commit 69308a3 into microsoft:main Sep 17, 2025
82 of 83 checks passed
@edgchen1

Copy link
Copy Markdown
Contributor

thanks for the PR!

naomiOvad pushed a commit to naomiOvad/onnxruntime that referenced this pull request Nov 2, 2025
…or (microsoft#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 <lifang.zhang@nokia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants