It is always said that the include directives should be placed at the beginning of a script. The main reason is to make the functions available throughout the script. Regardless of this fact, is it bad to place an include directive within the main function where it is needed?For example,#include <stdio.h>int main() {#include <mysql.h>}Instead of#include <mysql.h>#include <stdio.h>int main() {}I was unable to find any different in performance or compiled file size, but it is difficult to judge about this fact based on simple scripts. I wonder if it has any effect or drawback, or any reason to avoid this non-standard approach.
Is it bad to place include directive within main function?
c;scripting;compiling;include
It depends on what code   is in the include file.Did you try putting the #include for <stdio.h> inside main()? Depending on how the standard library is implemented on your system it may not even compile. Header files can contain not only function declarations, but function definitions. Standard C doesn't support nested functions.If your header file contains function and variable declarations, putting them inside the body of main() limits their scope. If the header file only contains preprocessor macros it might work, but you'll annoy all other C programmers by gratuitously moving the include somewhere unexpected. Coding standards are particularly important in C because C has so few safeguards to keep you from screwing up.