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 08-23-2006, 10:07 AM   #1
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Rep: Reputation: 30
headers,declarations,definitons


hello
i'm continuing a pretty big
project wich was not either
designed/thought/coded by me
earlier.

now i have to make some modules
to it.

for that purpose it is needed
to make .h and .c to accompany
the big project as a module.

the problem i am experiencing
is purely of convention ,but
it seems i cannot overcome it
by any means that i know of.

consider for example the following
files

<- will mean "contains"

main.c <- mi_core.h
mi_core.c <- mi_core.h

mi_fifo is a module wich
is structured like this

mi_fifo.c <- mi_fifo.h
mi_fifo.c <- tree.h
tree.c <- dbl_list.h
dbl_list.c<- dbl_list.h

this module mi_fifo is linked
and is separate from main.c.
mi_fifo is to be linked dynamically
with main.
(it is compiled as a .so file)

i have respected the convention that
all functions should be first declared
in .h and are to be defined(written) in
.c ,but i am keeping experiencing some
warnings at compilation(of mi_fifo).

../../mi_core.h:65: warning: ‘mi_trim_filename’ used but never defined

the above is the type of warning i keep
experiencing.

now if i include besides the .h the .c also
in this case i don't get the warning above
no more.

i should also mention that the .h is structured
as :

#ifndef _NAMEOFHEADERFILE_H
#define _NAMEOFHEADERFILE_H
<content_of_header_file>
#endif

this i understand that i must use so that this
header will not be processed twice,and it makes
sense to me

i would like to get some help on how to remedy
my problem
thank you

Last edited by spx2; 08-23-2006 at 10:09 AM.
 
Old 08-23-2006, 10:19 AM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
what does the declaration of mi_trim_filename look like? is it declared to be extern?
 
Old 08-23-2006, 10:22 AM   #3
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
oh and what is up with writing like you are a poet? or is your monitor resolution set at 50x75? if not could you try to type clear across the screen. i had to scroll down three times to read two sentences, pretty annoying..
 
Old 08-23-2006, 10:32 AM   #4
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Original Poster
Rep: Reputation: 30
static char *mi_trim_filename( char * file )
 
Old 08-23-2006, 11:20 AM   #5
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
almost sounds like you have the declaration in one lib and the definition in another. it gives a warning but does not fail because the linker is able to find the function in another lib that is linked in.

something like
Code:
header.h:
static char *mi_trim_filename( char * file );

main.c:
#include <header.h>
int main()
{
...
    mi_trim_filename(...);
...
}

other.c
char *mi_trim_filename( char * file )
{
    ... definition
}
you compile other.c and then compile it in with main.c, main's compile says that mi_trim is not defined, but the linker is happy because it finds mi_trim in other.o..

?? maybe
 
Old 08-24-2006, 04:46 AM   #6
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Original Poster
Rep: Reputation: 30
xhi first of all i would like to thank you for
looking at my post.

now let's hit the code,
mi_trim_filename is declared in a .h
and is defined in the corresponding .c(with
the same name as the .h),and in the same directory
 
Old 08-24-2006, 07:43 AM   #7
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
which .h file is it declared in?
 
Old 08-25-2006, 03:01 AM   #8
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Original Poster
Rep: Reputation: 30
mi_core.h is the header
 
  


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
errors on forward declarations. manikan Programming 11 02-03-2006 09:49 AM
C++ function declarations and definitions... AM1SHFURN1TURE Programming 2 08-29-2005 06:57 PM
Ambiguated definitons?!?!?!? starla827 Programming 3 03-26-2004 08:10 AM
Forward declarations somnium Programming 3 09-16-2003 05:00 AM
global declarations Randall Programming 50 03-15-2003 01:24 PM

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

All times are GMT -5. The time now is 05:06 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