473,385 Members | 1,838 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,385 software developers and data experts.

Multiple c files

Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.

Example if I have following files:
first.c
second.c
second.h(included in first.c)

I want a tool that would combine all the contents of these files in
one file

combined.c

Now if I compile combined.c I should get same result as original

Hope I am clear.
Thanks in advance
Nov 14 '05 #1
14 1931
vi*****@gmail.com (vishal) wrote in
news:2a**************************@posting.google.c om:
Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.


Yes, but this isn't really a question about the C language. You could use
things like 'cat' and the C pre-processor I suppose.

--
- Mark ->
--
Nov 14 '05 #2
In 'comp.lang.c', vi*****@gmail.com (vishal) wrote:
Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.

Example if I have following files:
first.c
second.c
second.h(included in first.c)

I want a tool that would combine all the contents of these files in
one file

combined.c

Now if I compile combined.c I should get same result as original

Hope I am clear.


I guess you can do that with any decent text editor... What exactly is your
point ? You also could automate the operation with some lines of C.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #3
"vishal" <vi*****@gmail.com> wrote in message
news:2a**************************@posting.google.c om...
Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.

Example if I have following files:
first.c
second.c
second.h(included in first.c)

I want a tool that would combine all the contents of these files in
one file

combined.c

Now if I compile combined.c I should get same result as original


You can usually output the intermediate file from the pre-processor. The
problem here is all your macros and #defines are parsed out, something like
"#define ESC 27" will be changed to 27 everywhere you had ESC in the code.

Microsoft has a couple of switches you can use like this: "cl /C /EP /u
prog.c > combo.c"

--
Mabden
Nov 14 '05 #4

"vishal" <vi*****@gmail.com> wrote in message news:

Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.

The problem is the "static" keyword. If you have static variables or
functions in the files then the tool will have to name-mangle to avoid a
clash.
Nov 14 '05 #5

"vishal" <vi*****@gmail.com> a écrit dans le message de
news:2a**************************@posting.google.c om...
Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.

Example if I have following files:
first.c
second.c
second.h(included in first.c)

I want a tool that would combine all the contents of these files in
one file

combined.c

Now if I compile combined.c I should get same result as original

Hope I am clear.
Thanks in advance


Merging two modules is a delicate operation. The crux of the matter is to
see
if there isn't any name-clashes, meaning if common names are used in the
same way.

1: static functions in the two modules could have the same name.
2: Macros could have the same name but different value/expansion.
3: One file could have a set of
#ifndef SOMESYMBOL
#endif
based in some symbol *not* being defined. If the other module defines
that
symbol, code could get included that it shouldn't.

Most of the time the merger is just adding the two source files, but watch
for the above problems. A simple way to check for those is to add
file a.c THEN file b.c. Compile, save the object file. Then, put first b.c
and THEN a.c. Compile and compare the object files.
They should be the same.



Nov 14 '05 #6

"Emmanuel Delahaye" <em**********@noos.fr> a écrit dans le message de
news:Xn***************************@212.27.42.66...
In 'comp.lang.c', vi*****@gmail.com (vishal) wrote:
Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.

Example if I have following files:
first.c
second.c
second.h(included in first.c)

I want a tool that would combine all the contents of these files in
one file

combined.c

Now if I compile combined.c I should get same result as original

Hope I am clear.
I guess you can do that with any decent text editor... What exactly is

your point ? You also could automate the operation with some lines of C.


This is surely not that simple. See my other post in this thread.
Just a word: "static". Doesn't that ring bells somewhere?
Nov 14 '05 #7

"Mabden" <mabden@sbc_global.net> a écrit dans le message de
news:Sr***************@newssvr25.news.prodigy.com. ..
[snip]
Microsoft has a couple of switches you can use like this: "cl /C /EP /u
prog.c > combo.c"


EP=preprocess to stdout, no #line, /u=remove all predefined macros
/C=don't strip comments

This will not cut it. The problem is "static", and other subtler
difficulties.
See my other post in this thread.
Nov 14 '05 #8
On Wed, 7 Jul 2004, Mark A. Odell wrote:
vi*****@gmail.com (vishal) wrote in
news:2a**************************@posting.google.c om:
Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.


Yes, but this isn't really a question about the C language. You could use
things like 'cat' and the C pre-processor I suppose.


Don't forget to deal with things like static global variables. They are
only visible to the translation unit. It is always possible that two
files contain a variable with the same name. Just concatenating the files
together is not guaranteed to work.

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
Nov 14 '05 #9
It seems that nobody has got my question correctly.
Let me elaborate.
We have a project package developed from many years that has about 200
files ( c files and header files ). Now we have a tool ( not developed
by us--only executable available with us ) that does take only 1 C
file as input at a time. Now that the whole code is distributed across
files I wanted one single "C" file with all code in it. As some of you
suggested cat or other editors, If I do it manually with these many
lines of code, the order of file, static functions, name clashes
everything is to be taken care off. So I raised a question in this
group asking for a solution.
Its ok for me if the tool does all the pre-processing. But I want a
single "C" file at the end which is as good as the whole package.

"jacob navia" <ja***@jacob.remcomp.fr> wrote in message news:<cc**********@news-reader4.wanadoo.fr>...
"vishal" <vi*****@gmail.com> a écrit dans le message de
news:2a**************************@posting.google.c om...
Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.

Example if I have following files:
first.c
second.c
second.h(included in first.c)

I want a tool that would combine all the contents of these files in
one file

combined.c

Now if I compile combined.c I should get same result as original

Hope I am clear.
Thanks in advance


Merging two modules is a delicate operation. The crux of the matter is to
see
if there isn't any name-clashes, meaning if common names are used in the
same way.

1: static functions in the two modules could have the same name.
2: Macros could have the same name but different value/expansion.
3: One file could have a set of
#ifndef SOMESYMBOL
#endif
based in some symbol *not* being defined. If the other module defines
that
symbol, code could get included that it shouldn't.

Most of the time the merger is just adding the two source files, but watch
for the above problems. A simple way to check for those is to add
file a.c THEN file b.c. Compile, save the object file. Then, put first b.c
and THEN a.c. Compile and compare the object files.
They should be the same.

Nov 14 '05 #10
vi*****@gmail.com (vishal) wrote in
news:2a**************************@posting.google.c om:
It seems that nobody has got my question correctly.
We understood. I think you are missing the point. The C language, the
topic of this newsgroup, does not specify how to do this. If there is such
a weird tool out there I suggest you employ google for help.
Let me elaborate.
We have a project package developed from many years that has about 200
files ( c files and header files ). Now we have a tool ( not developed
by us--only executable available with us ) that does take only 1 C
file as input at a time.


Why you would *ever* write a tool with such an awful limitation is beyond
reason.

--
- Mark ->
--
Nov 14 '05 #11
vi*****@gmail.com (vishal) wrote in message news:<2a**************************@posting.google. com>...
Is it possible using any tool to get a single C file containing a
combined code of multiple C files. The single file should include the
contents of the header file.

Example if I have following files:
first.c
second.c
second.h(included in first.c)

I want a tool that would combine all the contents of these files in
one file

combined.c

Now if I compile combined.c I should get same result as original

Hope I am clear.
Thanks in advance


<OT>
Hint: On many platforms you would be having a utility program
like @type@ or @cat@ to output the contents of the input stream to an
output stream. All you need to do is redirect them.
</OT>

HTH

--
Imanpreet Singh Arora
isingh AT acm DOT org
Nov 14 '05 #12
vishal <vi*****@gmail.com> wrote:
It seems that nobody has got my question correctly.
Let me elaborate.
We have a project package developed from many years that has about 200
files ( c files and header files ). Now we have a tool ( not developed
by us--only executable available with us ) that does take only 1 C
I get the feeling that you just ``switched'' from an IDE to a compiler.
Every compiler I've ever used compiles C files individually.
file as input at a time. Now that the whole code is distributed across
files I wanted one single "C" file with all code in it. As some of you
suggested cat or other editors, If I do it manually with these many
lines of code, the order of file, static functions, name clashes
everything is to be taken care off. So I raised a question in this
group asking for a solution.
Its ok for me if the tool does all the pre-processing. But I want a
single "C" file at the end which is as good as the whole package.


I strongly doubt that you've come up with a unique coding structure that
cannot be handled by conventional means. This magical solution you're
looking for sounds a lot like a linker to me. Perhaps you should try
using it to combine your C files *after* you've individually compiled
them into object files.
--
Peter Newman (pa******@uiuc.edu)
Nov 14 '05 #13
In 'comp.lang.c', vi*****@gmail.com (vishal) wrote:
We have a project package developed from many years that has about 200
files ( c files and header files ). Now we have a tool ( not developed
by us--only executable available with us ) that does take only 1 C
file as input at a time.
What the heck is that tool? Some interpeter?
Now that the whole code is distributed across
files I wanted one single "C" file with all code in it. As some of you
suggested cat or other editors, If I do it manually with these many
lines of code, the order of file, static functions, name clashes
everything is to be taken care off. So I raised a question in this
group asking for a solution.
Its ok for me if the tool does all the pre-processing. But I want a
single "C" file at the end which is as good as the whole package.


And how is this a good idea It breaks all known design rules about
modularity, testability, functionnal entities, code organization etc.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #14
vi*****@gmail.com (vishal) writes:
It seems that nobody has got my question correctly.
Let me elaborate.
We have a project package developed from many years that has about 200
files ( c files and header files ). Now we have a tool ( not developed
by us--only executable available with us ) that does take only 1 C
file as input at a time. Now that the whole code is distributed across
files I wanted one single "C" file with all code in it. As some of you
suggested cat or other editors, If I do it manually with these many
lines of code, the order of file, static functions, name clashes
everything is to be taken care off. So I raised a question in this
group asking for a solution.
Its ok for me if the tool does all the pre-processing. But I want a
single "C" file at the end which is as good as the whole package.


Please don't top-post. Your new text should follow any quoted text
from previous articles, as I've done here. Backwards read to
difficult it's.

The first thing I'd do is complain to whoever provided this tool
you're trying to use. C programs of any reasonable size are not, and
should not be, implemented in a single source file. A tool that
requires this is badly broken.

What is the tool supposed to do? If we knew that, we might have a
better idea of how to work around its limitations.

Automatically combining multiple C source files into an equivalent
single file is probably possible, but it's not easy. For example, two
source files in the same program might define static variables or
functions with the same name; joining them into a single file would
require changing at least one of the names and all references to it.
(Detecting all references is non-trivial; there could be declarations
with the same name in nested scopes that shouldn't be changed.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #15

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

Similar topics

6
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of...
2
by: Domenico Discepola | last post by:
Hello all. Before my arrival at my current employer, our consultants physically set up our MSSQL 7 server as follows: drive c: contains the mssql engine drive d: contains the transaction log...
3
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
5
by: vj | last post by:
Hi all, I am using C++Builder-5. I want to run multiple cpp files at the same time. If I use the C++Builder for running a cpp file (i.e., I just double click the cpp file, it then opens in the...
6
by: Steven | last post by:
I have a problem with moving the backup of my database from machine to machine. The size is 17 Gig and my network keeps timing out when I try to ftp it from machine to machine. I have had the...
2
by: Sam | last post by:
Hi All, I have a solution which consists of multiple projects and each of these projects has their own app.config file. The problem is that all of my projects in the solution pull keys from the...
10
by: kimiraikkonen | last post by:
Hi, I have an app which has a listbox and when i double click an associated fileS, i want their paths to be added into listbox in my application. This code works good when i try to open a...
3
by: Gary | last post by:
Hi all, I am writing an application which will intake arguments of filenames for processing: e.g. MyApp.exe "C:\abc.txt" "C:\def.doc" - then, MyApp will process the 2 files by parsing the...
43
by: bonneylake | last post by:
Hey Everyone, Well this is my first time asking a question on here so please forgive me if i post my question in the wrong section. What i am trying to do is upload multiple files like gmail...
4
by: MoroccoIT | last post by:
Greetings - I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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,...

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.