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, 1541👍, 0💬
Popular Posts:
Where are cookies actually stored on the hard disk? This depends on the user's browser and OS. In th...
What is the difference between Session State and ViewState? ViewState is specific to a page in a ses...
What is Service Oriented architecture? “Services” are components which expose well defined interface...
How To Avoid the Undefined Index Error? - PHP Script Tips - Processing Web Forms If you don't want y...
How do we enable SQL Cache Dependency in ASP.NET 2.0? Below are the broader steps to enable a SQL Ca...