LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A little problem with ANSI C and gcc (https://www.linuxquestions.org/questions/programming-9/a-little-problem-with-ansi-c-and-gcc-688291/)

SpLaSh212 12-04-2008 08:08 AM

A little problem with ANSI C and gcc
 
Hey guys,
I don't know whats the problem, I'm doing everything by the book (well, at least I think so)

I have a file calle "complex.h"
Code:

int check_complex(char ch);
void read_comp1(char ch, float n1, float n2);
void print_comp1(char ch);
void add_comp1(char ch1, char ch2);
void sub_comp1(char ch1, char ch2);
void mult_comp_real1(char ch1, float n);
void mult_comp_img1(char ch1, float n);
void mult_comp_comp1(char ch1, char ch2);
void abs_comp1(char ch);

and in the file "main.c"
Code:

#include <stdio.h>
#include <string.h>
#include <complex.h>


char ch1,ch2;
float n1,n2;

void read_comp(void)
{
        scanf("%c",&ch1);
        scanf("%f",&n1);
        scanf("%f",&n2);
        read_comp1(ch1,n1,n2);
}
...

when I compile the files with
Code:

ilia@debianIL:~/c-class/source/mmn/12/q2$ make
gcc -g -Wall -lm -o q2 main.c complex.c
main.c: In function ‘read_comp’:
main.c:16: warning: implicit declaration of function ‘read_comp1’

Does anyone know what is my mistake ? :\
thnx alot !

Sergei Steshenko 12-04-2008 08:17 AM

"complex.h" is a system include file, so, for starters, rename your file into something else.

johnsfine 12-04-2008 08:33 AM

Quote:

Originally Posted by Sergei Steshenko (Post 3364270)
"complex.h" is a system include file, so, for starters, rename your file into something else.

You might also want to use "" rather than <> around the name of your file.

I don't recall the exact search rules for include files, but in normal use, one sets up the search rules so that system wide header files are found when you use <> and your own header files are found when you use "".

SpLaSh212 12-04-2008 08:35 AM

ok,
thanks alot ! :)

jf.argentino 12-04-2008 10:23 AM

To complete johnsfine's explanation:
when you surround your header files with < and > it means that gcc will look into the system headers (/usr/include on GNU/linux), and on any path you provide to him with the -I option
when you surround your header files with double quotes, you must provide the complete header relative path in regard to the source file where you're making the #include.

johnsfine 12-04-2008 04:12 PM

Quote:

Originally Posted by jf.argentino (Post 3364432)
when you surround your header files with double quotes, you must provide the complete header relative path in regard to the source file where you're making the #include.

If I understand you correctly (relative path needed in the text given to #include) that is not true.

I haven't bothered this time to dig through the doc's, but I know from common usage that include directories can be given on the command line that will apply to #include lines using "". The important difference is that some places it searches for #include <> files automatically (with no command line switch needed) are not searched for #include "" files. The difference between <> and "" should also help anyone reading your code know whether you intended some system header file vs. some header file inside your own project.


All times are GMT -5. The time now is 09:35 PM.