1

I have a package with C code and a call to int checkInterrupt(); but devtools::check() says warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes].

How can I call the check interrupt function to pass that warning? I was thinking about checkInterrupt(void *dummy) but that doesn't work.

pachadotdev
  • 3,345
  • 6
  • 33
  • 60
  • 2
    Who defines `checkInterrupt`? You, or a third-party library, or your embedded OS, or what? Theoretically, you should introduce a proper prototype for it by #including the appropriate header file, not by hand-coding an external function declaration in each/every .c file where you use it. (That's [almost as error-prone](https://stackoverflow.com/questions/50401100) as not using prototypes at all.) – Steve Summit Jan 20 '23 at 20:55
  • 1
    Otherwise, you need to figure out what argument types `checkInterrupt` *actually* takes, and add those in the `()`. Don't just guess — that's *much* worse than not using prototypes at all! (And, by the way, `void *` does *not* mean "anything".) – Steve Summit Jan 20 '23 at 20:57
  • It is a part of R's C API (i.e., `#include `), and it's a function with no arguments – pachadotdev Jan 20 '23 at 20:57
  • 2
    `int checkInterrupt();` is not a function call — it is a declaration of a function returning an `int` but without a defined argument list (but it isn't a variadic function like `printf()` — its prototype would not end with `, ...`). And if you compile with `-Wstrict-prototypes`, such declarations are not allowed precisely because they don't define a prototype for the function. If the function takes no arguments, say so: `extern int checkInterrupt(void);`. And define it as `int checkInterrupt(void) { … }` too! (GCC options: `-Wold-style-definition` and `-Wold-style-declaration`). – Jonathan Leffler Jan 20 '23 at 21:04
  • 1
    Note that these rules will change with C23 — it will follow the C++ rules so that a declaration with an empty parameter list will be the same as one with `(void)` as the parameter list, and the declaration will provide a prototype for the function. – Jonathan Leffler Jan 20 '23 at 21:06
  • 3
    @pachadotdev In that case, if you have `#include `, you don't need the line `int checkInterrupt();` at all, and you can delete it, and that should make the warning go away. – Steve Summit Jan 20 '23 at 21:24
  • 1
    To actually call the function, rather than declare it, simply use `checkInterrupt();` (no type before it). That calls the function with no arguments. As long as it has been declared before it is called, all will be well. Maybe you should check the returned value, though — it probably has some significance and maybe your code should respond to that. – Jonathan Leffler Jan 20 '23 at 21:54
  • 1
    @JonathanLeffler does that mean that `main` will become a dynamic function, in that it changes at run-time based on whether it is declared `main()` or `main(int argc, char **argv)`? – user129393192 Apr 29 '23 at 21:10
  • 1
    @user129393192 — I'm not sure what you mean by a 'dynamic function'. The standard says that a hosted implementation (the normal kind) does not provide a prototype for `main()` and must support both `int main(void)` and `int main(int argc, char **argv)` (or equivalents) and may support other implementation-defined signatures. One such variation is listed in Annex J.3 (Common extensions). See also [What should `main()` return in C and C++?](https://stackoverflow.com/q/204476/15168) – Jonathan Leffler Apr 30 '23 at 05:25
  • 1
    All I meant is that the prototype for it changes with compilation. The reason I thought this wouldn't work in C23 is because I thought `main()` means an undefined number of arguments, so its compatible with the one where you put arguments in. I guess I don't really understand why `()` means undefined number of arguments in first place and what the use case for it is, since I had thought that the `main()` function was the primary use-case. – user129393192 Apr 30 '23 at 19:53

0 Answers0