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, 1557👍, 0💬
Popular Posts:
What is Traceability Matrix? Traceability Matrix is one of the document will prepare by QA.To make s...
How do we get the current culture of the environment in windows and ASP.NET? “CultureInfo.CurrentCul. ..
Explain all parts of a deployment diagram? Package: It logically groups element of a UML model. Node...
How To Create an Array in PL/SQL? - Oracle DBA FAQ - Introduction to PL/SQL If you want create an ar...
What is the method to customize columns in DataGrid? Use the template column.