C functions visibility -


how make c function visible functions in other certains .c files?

let's suppose have foo1 function wich calls other foo2 function (in differents .c files) , want call foo1 main function, want foo2 invisible function other foo1, this:

/**     foo1.c */ void foo1() {     if (condition_is_true){         foo2();     } }  /**     foo2.c */ #include <stdio.h>  void foo2() {     printf("hello world!\n"); }  /**     main.c */ void foo1(void); void foo2(void);  int main() {     foo1();     foo2(); /*unresolved external*/ } 

and when compiling

$ cc -omain main.c foo1.c foo2.c 

i want linker complain "undefined reference `foo2'".

usually, if want make function in 1 .c source code file visible in .c source file, place definition of function .h file , include .c file want visible in. example:

file foo1.c int somefunc1(some parameters)   {     stuff.   }  file foo1.h int somefunc1(some parameters);  file foo2.c #include "foo1.h"  int foo2(some parameters)   {     stuff.     foo1(asdfasdf)     more stuff.   } 

that do. however, asking exact opposite. i'm not sure why want undefined reference when linker runs, way have set compile, files passed linker. thing can not have foo2.c on file list. if using 1 of main libraries, still gets linked in if don't specify include file. instance:

$$$ ->more test3.c  int main(void)   {     printf("hello world\n");     return(0);   }   $$$ ->clang -std=c11 -wall -wextra -o test3 test3.c test3.c:8:5: warning: implicitly declaring library function 'printf' type 'int (const char *, ...)'     printf("hello world\n");     ^ test3.c:8:5: note: please include header <stdio.h> or explicitly provide declaration 'printf' 1 warning generated. 

so asking don't think can or should done.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -