Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
My ANSI compiler complains about a mismatch when it see
My ANSI compiler complains about a mismatch when it sees
extern int func(float);
int func(x)
float x;
{ ...
✍: Guest
You have mixed the new-style prototype declaration ``extern int func(float);'' with the old-style definition ``int func(x) float x;''. It is usually possible to mix the two styles but not in this case.
Old C (and ANSI C, in the absence of prototypes, and in variable-length argument lists;`widens'' certain arguments when they are passed to functions. floats are promoted to double, and characters and short integers are promoted to int. (For old-style function definitions, the values are automatically converted back to the corresponding narrower types within the body of the called function, if they are declared that way there.) Therefore, the old-style definition above actually says that func takes a double (which will be converted to float inside the function).
This problem can be fixed either by using new-style syntax consistently in the definition:
int func(float x) { ... }
or by changing the new-style prototype declaration to match the old-style definition:
extern int func(double);
(In this case, it would be clearest to change the old-style definition to use double as well.
It is arguably much safer to avoid ``narrow'' (char, short int, and float) function arguments and return types altogether.
2016-01-13, 1569👍, 0💬
Popular Posts:
How do you override a defined macro? You can use the #undef preprocessor directive to undefine (over...
What's wrong with this initialization? char *p = malloc(10); My compiler is complaining about an ``i...
How To View All Columns in an Existing Table? - Oracle DBA FAQ - Managing Oracle Database Tables If ...
In C#, what is a weak reference? Generally, when you talk about a reference to an object in .NET (an...
How is the MVC design pattern used in Struts framework? In the MVS design pattern, there 3 component...