473,809 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1893
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
2234
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... Here's what I think of how it is (from what I've read): THE PROJECT +1st header file
31
2809
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 http://www.kdevelop.org http://www.suse.com http://www.mozilla.org
16
12551
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 because it is, as the authors love to say, "implementation specific". If that's the case, how does the compiler commonly handle them? I use Linux and gcc specifically. Basically, I don't understand how a header file being included makes a...
11
2765
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 understand the objective. This example may represent an interface in need of a bit of refactoring, but it goes to demonstrate the basic idea as I understand it. http://developer.kde.org/documentation/library/cvs-api/kdevelop/html/ast_8h-source.html...
60
8326
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 associated with this source file For example, in a file hello.c: #include <stdio.h>
4
2517
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 usage of a large third party library which means after pre-processing each translation unit is around 1meg in size. There are reasons though why I cannot use the standard approach to precompiled headers. What I would like to do is somthing like...
0
3946
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
16
2092
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 and permutations use factorial to solve their problems, factorial is supposed to be in both perm.c and combo.c, and declared private. (1) You wouldn't ever put a prototype in a header if that function was
1
24170
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 header from script. Bad header= : padata.pl /perl/pema/padata.pl did not send an HTTP header 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
8049
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 below. I do not add any www-authentication header here so I was wondering if anyone knows how to remove it. I have used almost 2 days trying to figure this out so help would be highly appreciated. CORRECT No proxy-authenticate header is present no...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10635
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10378
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7653
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.