473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

header file

Sorry for inconvenience!

I have two sourcefiles file1.c and file2.c. file1.c codes the standard BST
(binary search tree) functions declarations and the basic struct definition.

file2.c has some special functions, I want to implement for exercise
purposes.

In my opinion gcc file1.c file2.c should do the linking. But the compiler is
complaining, because it doesn't know about the struct and it's pointers
(file2.c).

I tried to write a header to include file2.c. But the #include prepocessor
is before the struct and still the functions in file2 don't know about the
struct.

I would appreciate if someone can give me a hint, how to make this known and
cease my confusion.

Thank you,

Ernst

do*******@ulcus.owl.de

Feb 17 '07 #1
3 1873
virgincita schmidtmann said:
Sorry for inconvenience!

I have two sourcefiles file1.c and file2.c. file1.c codes the standard
BST (binary search tree) functions declarations and the basic struct
definition.

file2.c has some special functions, I want to implement for exercise
purposes.
Put struct definitions and prototypes into a header, e.g. bst.h, and
#include that header into both C files. Don't put function bodies or
data definitions into the header, though.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 17 '07 #2
virgincita schmidtmann wrote:
Sorry for inconvenience!

I have two sourcefiles file1.c and file2.c. file1.c codes the standard BST
(binary search tree) functions declarations and the basic struct definition.

file2.c has some special functions, I want to implement for exercise
purposes.

In my opinion gcc file1.c file2.c should do the linking. But the compiler is
complaining, because it doesn't know about the struct and it's pointers
(file2.c).

I tried to write a header to include file2.c. But the #include prepocessor
is before the struct and still the functions in file2 don't know about the
struct.

I would appreciate if someone can give me a hint, how to make this known and
cease my confusion.
You haven't clearly specified where your declarations are and which
file expects which declaration. I suggest seperating all the
neccessary declarations into a third header file, named as say
project.h and include this in both file1.c and file2.c. In most cases
you should not include *.c files into other files. You should try to
seperate the relevant declarations and definitions from the somename.c
file into a somename.h file and include the latter wherever
neccessary.

Compile each of your modules seperately into object code and do the
linking at the end. The command for doing that in gcc might be like:

gcc -c file1.c
gcc -c file2.c
gcc -o a.out file1.o file2.o

Also consider instructing the compiler to strictly adhere to standard
C and check for suspicious constructs by passing the -Wall, -Wextra, -
ansi and -pedantic flags. You can also use the -std=XX (XX being c89
or c99) flag instead of -ansi.

Feb 17 '07 #3
Thanks a lot to Richard and you!

Actually, when I had written the post I realised a way to do that. The
problem was some kind of circle dependencies, which I could resolve
by building two header files. By the way, now I understand the meaning
of ifndef, etc. ...

However, one week of thinking and after writing the problem in a post
I could resolve it. Funny

Thanks a load again,

Ernst

santosh wrote:
>
You haven't clearly specified where your declarations are and which
file expects which declaration. I suggest seperating all the
neccessary declarations into a third header file, named as say
project.h and include this in both file1.c and file2.c. In most cases
you should not include *.c files into other files. You should try to
seperate the relevant declarations and definitions from the somename.c
file into a somename.h file and include the latter wherever
neccessary.

Compile each of your modules seperately into object code and do the
linking at the end. The command for doing that in gcc might be like:

gcc -c file1.c
gcc -c file2.c
gcc -o a.out file1.o file2.o

Also consider instructing the compiler to strictly adhere to standard
C and check for suspicious constructs by passing the -Wall, -Wextra, -
ansi and -pedantic flags. You can also use the -std=XX (XX being c89
or c99) flag instead of -ansi.
Feb 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Mantoulidis | last post by:
Seperate compilation (that's what it's called, right?) seems to be quite popular, so I decided to get some info about it, and (d'oh) use it... But it's whole structure seems weird to me... ...
31
by: Steven T. Hatton | last post by:
If a header is not necessarily a source file, and the sequences delimited by < and > in header names aren't necessarily valid source file names, what exactly is a header? -- p->m == (*p).m == p.m...
16
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
4
by: Andrew Ward | last post by:
Hi All, I was wondering if it is possible to use precompiled headers without having to include a <stdafx.h> or whatever in every source file. My problem is that I have a project that makes heavy...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
16
by: wdh3rd | last post by:
Hi everyone. I'm new to C and I have a few questions: I am making files for permutations and combinations. Files to be made are perm.c, perm.h, combo.c, and combo.h. Since both combinations...
1
by: Shalako | last post by:
I check my error log and see these entries: malformed header from script. Bad header= Missing gauge reports are ind: padata.pl /perl/pema/padata.pl did not send an HTTP header malformed...
1
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.