| Electronic Components Datasheet Search |
|
AN3350 Datasheet(PDF) 131 Page - STMicroelectronics |
|
|
|||||||||||||||||||||||||||||
AN3350 Datasheet(HTML) 131 Page - STMicroelectronics |
|
131 / 185 page ![]() AN3350 Pragmas for standard C conformance Doc ID 018512 Rev 2 131/185 caused by referring to a function before you define it. For example, without a function prototype, you might pass data of the wrong type. As a result, your code might not work as you expect even though it compiles without error. In Example 80, function main() calls PrintNum() with an integer argument even though PrintNum() takes an argument of type float. Example 80 Unnoticed type-mismatch #include <stdio.h> void main(void) { PrintNum(1); /* PrintNum() tries to interpret the integer as a float. Prints 0.000000. */ } void PrintNum(float x) { printf("%f\n", x); } When you run this program, you could get this result: 0.000000 Although the compiler does not complain about the type mismatch, the function does not give the result you intended. Since PrintNum() does not have a prototype, the compiler does not know to generate instructions to convert the integer to a floating-point number before calling PrintNum(). Consequently, the function interprets the bits it received as a floating-point number and prints nonsense. A prototype for PrintNum(), as in Example 81, gives the compiler sufficient information about the function to generate instructions to properly convert its argument to a floating- point number. The function prints what you expected. Example 81 Using a prototype to avoid type-mismatch #include <stdio.h> void PrintNum(float x); /* Function prototype. */ void main(void) { PrintNum(1); /* Compiler converts int to float. } Prints 1.000000. */ void PrintNum(float x) { printf("%f\n", x); } In other situations where automatic conversion is not possible, the compiler generates an error message if an argument does not match the data type required by a function prototype. Such a mismatched data type error is easier to locate at compile time than at runtime. |
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |