473,659 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to organize files to write include?

Hi all

look at the organize tree

main.c
------
#include lib_adapter.c
main()
{
foo();
}
lib_adapter.c
-------------
#include "foo_liba.c "
#include "foo_libb.c "

void foo(){
#ifdef USING_LIBA
foo_liba()
#endif
#ifdef USING_LIBB
foo_libb()
#endif
}

void need();
lib_a.c
=======
void foo_liba()
{
need();
}

lib_b.c
-------
void foo_libb()
{
need()
}
gcc -o main main.c lib_adapter.c lib_a.c lib_b.c
the code can not be complained , what I want to know is

I can not put need() out side of the lib_adapter.c
1.how to write include structure
2.need I have to write .h file instead of include c file?

best regards
your key9


Sep 15 '06 #1
2 3527
key9 wrote:
Hi all

look at the organize tree
Sounds like a troll already.
Bad engrish, lack of caps, etc.
>
main.c
------
#include lib_adapter.c
main()
{
foo();
}
lib_adapter.c
-------------
#include "foo_liba.c "
#include "foo_libb.c "

void foo(){
#ifdef USING_LIBA
foo_liba()
#endif
#ifdef USING_LIBB
foo_libb()
#endif
}

void need();
lib_a.c
=======
void foo_liba()
{
need();
}

lib_b.c
-------
void foo_libb()
{
need()
}
gcc -o main main.c lib_adapter.c lib_a.c lib_b.c
some of the problems:

1. main should return an int.
2. Include files should not contain executable code.
You want to end up with one copy of each function,
and putting code in include files causes the function
to be expressed every time you include the file,
causing the linker to be upset about multiple definitions.
3. Include files should end in a '.h' extension.
It's a convention, and most C programmers expect it.
This allows for a 'cc *.c -o xxx' at the command line
to compile most simple programs.
4. Since lib_adapter.c, lib_a.c, and lib_b.c are all
included in main.c, why are you compiling them a
second time?
5. main should return a value.
6. need() is not implementated anywhere.
7. Neither "USING_LIBA " nor "USING_LIBB " are defined,
thus foo() is a null function.
8. need() is prototyped after use, instead of before.
....
the code can not be complained , what I want to know is
Why can't it be complained. I see lots of things to complain about.
What errors do you get? Are we supposed to guess?
>
I can not put need() out side of the lib_adapter.c
What happens when you try? What error do you get?
>

1.how to write include structure
2.need I have to write .h file instead of include c file?
You don't seem to really understand the purpose of
include files.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Sep 15 '06 #2
key9 wrote:
Hi all

look at the organize tree

main.c
------
#include lib_adapter.c
Although omitting <or "" may work on your compiler, it is not conforming.
main()
{
foo();
}
lib_adapter.c
-------------
#include "foo_liba.c "
#include "foo_libb.c "

void foo(){
#ifdef USING_LIBA
foo_liba()
#endif
#ifdef USING_LIBB
foo_libb()
#endif
}

void need();
lib_a.c
=======
void foo_liba()
{
need();
}

lib_b.c
-------
void foo_libb()
{
need()
}
gcc -o main main.c lib_adapter.c lib_a.c lib_b.c
the code can not be complained , what I want to know is

I can not put need() out side of the lib_adapter.c
Do you mean that gcc does not give error messages or warnings? If not,
I can't interpret your comment.
1.how to write include structure
Questions should have a subject, verb, and end in a question mark, as
well as ask a question: "How can I include a structure in my program?"
That might not be the question you intended to ask. I think you are
asking about how to use #include statements in a program.

By convention, C programs are separated into code files and declaration
files. The code files contain function definitions and normally have an
extension of .c. The declaration files have declarations normally used
by multiple code files and have an extension of .h. These naming and
organizational conventions are not requirements of the language, though,
and compilers don't care what extensions are used on the files.

Normally .c files are each compiled into a separate object file, then
the object file are linked into a single executable file. In contrast,
I have used a C dialect compiler (for small microprocessors ) that
requires all code files to be compiled together -- it cannot compile to
object files and link. For that compiler, it is typical to have a main
file include other code files. This is not recommended for normal use,
though.
2.need I have to write .h file instead of include c file?
No. In general you should compile code files separately and link them.
I recommend writing a header file for each code and placing the
prototypes (and other definitions required to use the code module) in
the associated header file. Then include the header file in both the
code file defining the functions and code files using the defined functions.

I suggest finding a good text book on C.

--
Thad
Sep 16 '06 #3

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

Similar topics

10
11066
by: Bruce W...1 | last post by:
I've been learning about PHP for a couple of weeks. With includes, PHP scripts, and HTML I can see where a large and complex website could easily turn in to a big hairy mess with files all over the place. Are there any adopted standards, recognized recommendations, or best practices on how all the code should be organized? I haven't found any websites that discuss this. Can anyone point me to information on this? If not then what do...
3
2278
by: _andrea | last post by:
I'd like to write a web-application with other people. It is the first time I write code together other person. I'd like to ask you some advices: 1)have an advice? 2)wich program to use for VCS (for windows)? 3)how to organize the work? Thank you in advance, Andrea.
10
9910
by: TokiDoki | last post by:
Hello there, I have been programming python for a little while, now. But as I am beginning to do more complex stuff, I am running into small organization problems. It is possible that what I want to obtain is not possible, but I would like the advice of more experienced python programmers. I am writing a relatively complex program in python that has now around 40 files.
1
3378
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or suggestion for improvements or conversion to iteration would be much appreciated
2
1870
by: key9 | last post by:
Hi all on last post I confused on how to organize file of class, ok ,the problem solved : should include class define head on cpp file. but this time ,still link error: strange is I put the implement to .h file directly like this: *******head file***** class LinuxTestTerminal : public Terminal{ public:
1
1353
by: chellemybelle | last post by:
Hello Java Forum, I am writing an applet to display a menu with various text fields, buttons, and such. I wanted to know if you could help me to organize my classes. My limited logic in this subject thinks I should write one class to design my panel, and a button handler class to extend the panel class that implements listener(which would include my instance variables for the various menu functions). Would that cover it? Also, when i design my...
1
1671
by: JRough | last post by:
I have includes at the top of the file and I have inline includes also includes in mysql queries. For example: include './includes/config.inc.php'; include $include_path.'dates.inc.php'; include $include_path.'auction_types.inc.php'; include $include_path.'countries.inc.php'; include $include_path.'datacheck.inc.php'; include $include_path.'wordfilter.inc.php'; include $include_path.'converter.inc.php';
0
1156
by: Dudeja, Rajat | last post by:
Hi, I'm learning Python to write a GUI application using Tkinter & Tk. I've evaluated Eclipse and Pydev. With the help of Fabio Zadrozny I successfully installed Eclipse and PyDev. Thanks. Now, I'm learning Eclipse and PyDev. And my problem is that I don't have an understanding of how the code in
2
2478
by: Fredrik Lundh | last post by:
Dudeja, Rajat wrote: A Python program consists of a script file (the py file you run to start the program), and usually one or more additional module files (py files that you import). The latter can be organized in packages, where appropriate. There's also a search path (sys.path) that you can modify in various ways (including from within the program) if you want to fetch modules from different locations.
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
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
6179
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
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.