473,320 Members | 1,910 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,320 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 1869
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.