Advertisement
Manhydra

Static Function Example

Sep 6th, 2013
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. /* test-module.c */
  2. static int privateValue = 15;
  3.  
  4. static int getValue() {
  5.     return privateValue;
  6. }
  7.  
  8. static void setValue(int val) {
  9.     privateValue = val;
  10. }
  11.  
  12. int getPrivateValue() {
  13.     return getValue();
  14. }
  15.  
  16. void setPrivateValue(int val) {
  17.     setValue(val);
  18. }
  19.  
  20. /* main.c */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25. #define valueOf(f, x) printf("Test: "#x" = %"#f"\n", x)
  26.  
  27. int main(int argc, char **argv) {
  28.     setValue(5); /* undefined reference to `setValue' */
  29.     valueOf(d, getValue()); /* undefined reference to `getValue' */
  30.  
  31.     setPrivateValue(10);
  32.     valueOf(d, getPrivateValue());
  33.  
  34.     exit(EXIT_SUCCESS);
  35. }
  36.  
  37. /* Compilation */
  38. gcc -g -O2 -o testing test-module.c testing.c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement