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, 1124👍, 0💬
Popular Posts:
How can I implement a variable field width with printf? That is, instead of something like %8d, I wa...
What is the difference between mysql_fetch_object() and mysql_fetch_array() functions in PHP? mysql_...
What Is a LABEL Tag/Element? - XHTML 1.0 Tutorials - Understanding Forms and Input Fields A "label" ...
What is a fish bone diagram ? Dr. Kaoru Ishikawa, invented the fishbone diagram. Therefore, it can b...
How To Check the Oracle TNS Settings? - Oracle DBA FAQ - ODBC Drivers, DSN Configuration and ASP Con...