LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-04-2008, 08:08 AM   #1
SpLaSh212
Member
 
Registered: Mar 2006
Posts: 42

Rep: Reputation: 15
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 !
 
Old 12-04-2008, 08:17 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
"complex.h" is a system include file, so, for starters, rename your file into something else.
 
Old 12-04-2008, 08:33 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Sergei Steshenko View Post
"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 "".
 
Old 12-04-2008, 08:35 AM   #4
SpLaSh212
Member
 
Registered: Mar 2006
Posts: 42

Original Poster
Rep: Reputation: 15
ok,
thanks alot !
 
Old 12-04-2008, 10:23 AM   #5
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
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.
 
Old 12-04-2008, 04:12 PM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by jf.argentino View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read F1,F2 in Ansi C? john.daker Programming 4 11-05-2008 09:36 AM
ANSI cotes problem bogoda Linux - Software 3 02-23-2006 11:11 PM
what ANSI C++ version does gcc 3.2.3 conform to? kmullin Programming 1 05-26-2004 02:32 PM
Ansi Telnet thebutler4 Linux - Software 1 05-25-2004 12:58 PM
ANSI C Manual rajaram Programming 6 01-05-2002 07:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration