03-19-2021 10:13 AM
Hi all!
If I compile and run (!) this remarkably complex 😉 piece of code, I have no warning and no issues.
Microsoft C++ compiler hasn't the same point of view, and complains with the missing HelloWorld function and I agree with him. 😎
We are too strict, or LabWindows 20.0 has a nasty bug? 😓
#include <stdio.h>
static void HelloWorld(int x);
void main()
{
HelloWorld(42);
}
static void HelloWorld()
{
printf("I don't care about stupid parameters\n");
}
Best regards
03-19-2021 11:38 AM
I have tried it in the Interactive Execution window and I do get errors...
3, 1 error: function declared in block scope cannot have 'static' storage class
03-19-2021 05:43 PM
Wolfgang, have you focused on the parameter passed to the function?
I have found this interesting analysis: apparently CVI is strictly following C rules which permit such a situation.
BTW, CVI2012 complains about the () definition rasing a 'missing prototype' error: may this "feature" depend the switch to clang?
03-20-2021 02:31 AM
Hi Roberto 😁
Thanks for your link - so I have learnt something new, declaring a function with no argument is different from declaring it with void... actually until now I thought that a declaration without an argument (i.e., without specifying void) would not be valid...😯
Yes, and I also was very surprised to see the example given, once the function with and once without an argument...
btw, the compiler error I reported is from CVI 2020
03-22-2021 11:11 AM
Wolfgang,
I have learnt something new too! I was puzzled as well as you about that function definition but after some search I bumped into that page and had to add this to the list of things to check while coding.
I never faced this problem since I have the habit of using void for functions that do not accept parameters.
03-22-2021 11:18 AM
Wolfgang; 'static' keyword is not absolutely mandatory in my example, behavior is exactly the same without it. I would expect that storage classes and so on don't work in interactive window.
Roberto: as from your link, my code is not a "noncompliant code" according to both examples. I have declared a full prototype, even called it, but the function code has an empty parameter list.
After further research, that code should not is allowed according to what is stated in point 14 of paragraph 6.7.5.3 of C99 standard:
"An identifier list declares only the identifiers of the parameters of the function.
An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.
The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the
parameters is supplied."
Thus, compiler sees a function definition that has a different parameter list (i.e. empty) from its declaration and it does not complain at all.
This a bug, IMHO.
C99 standard