Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -------------------------------------------------------------------------------------------
- Error:
- $ gcc -std=c99 -Wall tddc.c && ./a.out
- /tmp/ccXPmsC6.o: In function `sum_test':
- tddc.c:(.text+0x13): undefined reference to `calc_sum'
- tddc.c:(.text+0x44): undefined reference to `calc_sum'
- collect2: ld returned 1 exit status
- But if I do...
- $ gcc -std=c99 -Wall calc.c tddc.c && ./a.out
- It works! Why doesn't the first one autoresolve calc.h and calc.c?
- ------------------------------------------------------------------------------------------- */
- // Calc unit test
- // tddc.c
- #include "calc.h"
- #include <assert.h>
- #include <stdbool.h>
- static void sum_test() {
- int sum;
- sum = calc_sum(1,30);
- assert(sum == 31 && "test_sum: positive sum");
- sum = calc_sum(1,-30);
- assert(sum == -29 && "test_sum: negative sum");
- }
- int main() {
- sum_test();
- }
- //------------------------------------------------------------------------------------------
- // calc.h
- int calc_sum(int oper1, int oper2);
- //------------------------------------------------------------------------------------------
- // calc.c
- #include "calc.h"
- int calc_sum(int oper1, int oper2) {
- return oper1 + oper2;
- }
Add Comment
Please, Sign In to add comment